|
Building on what leppie and Daniel have said:
You cannot use const in conjunction with your own data types* because they need to be complete at compile time. You can however use readonly with your own data types.
Another scenario is instances where something should be treated as a constant but can't because the constant can change depending on certain behavior. For instance, a class which will perform currency conversion; depending on the two currencies being converted the factor will differ. You can of course expose this factor as a read-only property, but there is nothing to stop your code from changing that value once an instance has been created. If you make the factor readonly though the compiler will ensure you don't change the factor after creating an instance of the class.
Bad example, I know, but just one possibility
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
I am having problems creating large Bitmap object. I am using the Bitmap class in C# and my application requires the creation of a large (greater than 46340 x 46340) image. During execution of:
Bitmap bmp = new Bitmap(width, height);
I get the System.ArgumentException when the width value is set to 46341 and the height value is set to 46341. I dont get this error if the imagesize is 46340x46340. I understand that I am crossing the limit of a signed 32bit integer with the value of 46341x46341. Is this a limiting factor? How do I get around this problem.
I would appreciate any help.
Thank you.
-SpinD
|
|
|
|
|
If this is not a monochrome bitmap, i.e. 1 bit per pixel, then give up now. You only have 2GB of address space to work with using the current CLR on Win32. Even an 8bit palette image of that size would no longer fit in memory.
If you really need to work with images that size obviously you aren't displaying them on the screen, so don't try to load them all into memory. Don't use Bitmap; treat them as data on the disk.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Hi
How can i access COM Ports in C#
raheela
|
|
|
|
|
Perhaps this[^] would help.
Beyond that, there are probably some other samples on www.gotdotnet.com[^] but that one looked the most promising in a search for com port another search that might work well is one for serial port.
Good luck,
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
Hi all,
I'm working in a project that uses DataSets and I found a trouble shotting trying to set up in ordering a column of a table contained in the data set, in order to achive I use DataViews, this DataView works perfecly, then I retun the ordered data to the DataSet and then retun this DataSet as WebMethod but the data does simple not work, do anyone know what is the problem??, here is an code of my development...
tnks
public DataSet MyMethod(DataSet myDS)
{
// this data view is working perfecly
DataView myDView = new DataView(myDS.Tables[tablename], "", <column asc="">, DataViewRowState.CurrentRows);
// I'm doing this remove because if doesn't it causes assignment problems
myDS.Tables.Remove(tablename);
// I'm trying to assign the ordered data to the DataSet
myDS.Tables.Add(myDView.Table);
return myDS;
}
// in this web method does not work properly
[WebMethod]
public DataSet Test()
{
...
DataSet DS = MyMethod(myDS)
return DS;
}
/*********** Om@r ***********/
|
|
|
|
|
Please tell me more about why do you remove and then re-add the table TableName. This can't make sense!
Stefan
|
|
|
|
|
Stefan,
Because if you don't remove it, it results in a read only assign error due to the dependency of the table with the dataview. Yesterday I discover that dataview is in fact a memory pointer table that can not be assigned to any other data struct, try doing a test with a code similar to my code without the removing action and see what happens...
Omar
/*********** Om@r ***********/
|
|
|
|
|
Omar,
So please tell me what you want to do practically. I'm sure that you don't have to remove and re-add your table.
Maybe I can help you.
Stefan
|
|
|
|
|
Stefan
I'm using a method class that receive a dataset, the name or index of a table and the name or index of a columname and the order, I need to retrieve the DataSer ordered by the column indicated, I can not doing this in a DataGrid because the data is not going to be a web method and this data is going to passed to other layer in the structure, also I can not handle the order in the data base because this data table is composed by more than one table of diferent data base tables and computed columns, so in resume, I need to return this DataSet (or a new one) but with the table in question ordered, could you help me about this??
Omar
/*********** Om@r ***********/
|
|
|
|
|
public DataSet YourMethod(String Table, String Column or DataColumn dc)
DataTable dt=DataSet.Tables[Table];
DataRow[] rows=dt.Select(strExpr, Sort, RowState)
better:
DataSet.Tables[Table].DefaultView.Sort="ColumnName DESC";
Perhaps you don't know that you can bind your DataGrid to a DataView, too!
DataGrid.DataSource=DataSet[Table].DefaultView;
If I did not understand your needs try to reexplain or use another language to tell me. German or French, perhaps?
|
|
|
|
|
Dear STW
Finally I found the solution for my problem, I was pointed to erroneus table and row pointer, here is the complete solution...
Basicly I needed a method which receives a dataset, table name, column name and type order and the return the same (or in a diferente dataset) the same table contained in a data set but ordered by meaning of the column name and type order (Desc / Asc), as I told you, I can not simply Bind the DataView value to a DataGrid because I need to pass a DataSet to other upper layer that performs other transformation for this DataSet like formating, including / excluding columns, etc. Also I could not handle it in the data base (ordering directly the table) because the data set table composed by differents source data like computed columns, added columns from other data bases, etc. That's why a needed to handle this in a Data Set form...
regards and thanks for all...
/************************************************************************/
Private Function OrderTable(DataSet, tablename, columnname, typeorder) As DataSet
Dim ds1 As New DataSet
Dim dt As DataTable
Dim dv As DataView
Dim dr1 As DataRow
Dim a As Integer
Dim drv As DataRowView
dv = ds.Tables(0).DefaultView
dv.Sort = strCol + " " + strOrder
dt = ds.Tables(0).Clone
For Each drv In dv
dr1 = dt.NewRow
For a = 0 To dv.Table.Columns.Count - 1
dr1(a) = drv(a)
Next
dt.Rows.Add(dr1)
Next
Dt.tableName=strTabla
ds1.Tables.Add(dt)
Return ds1
End Function
/*******************************************************************/
/*********** Om@r ***********/
|
|
|
|
|
So you make a View and then copy the sorted rows to another DataTable. Your solution is to create a new DataTable.
Good luck
Stefan
|
|
|
|
|
Hi, having some trouble incoking LogonUser, here's the code fragment.
int token;
bool loggedOn = LogonUser(
"CustomAppUser", //Username
"AA02", //Computer name
"customappuser", //Passwd (Remember, this is case-sensitive.)
3, //Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
0, //Logon provider = LOGON32_PROVIDER_DEFAULT.
out token //token for the specified user.
);
int ret = GetLastError();
if(ret!=0)
{
Console.WriteLine("Impersonation error. Error code: " + ret.ToString());
return;
}
Error from GetLastError is "203". After a bit of searching, I suspect that LogonUser call LoadUserProfile internally. Reference:
http://support.microsoft.com/default.aspx?scid=KB;en-us;305136&
But I'm not sure how to pinvoke LoadUserProfile... parameter such as "Handle" and "LPPROFILEINFO"... How can I call LoadUserProfile from C#?
Reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/policy/policy/loaduserprofile.asp
Thanks!
norm
|
|
|
|
|
I invoked LoadUserProfile before call LogonUser - it failed to solve the problem. GetLastError still returns error 203 after LogonUser.
Here's how I did it:
//MSDN Sample: http://msdn.microsoft.com/vstudio/using/understand/interop/default.aspx?pull=/library/en-us/dnnetsec/html/SecNetHT13.asp
const int SecurityImpersonation = 2;
IntPtr dupeTokenHandle = DupeToken(
WindowsIdentity.GetCurrent().Token,
SecurityImpersonation); //CAUTION: Current user is different from the user I wish to impersonate.
if(IntPtr.Zero == dupeTokenHandle)
{
Console.WriteLine("Unable to duplicate token.");
}
PROFILEINFO profile = new PROFILEINFO();
profile.dwSize = 32;
profile.lpUserName = "AA02\\CustomAppUser";
bool retval = LoadUserProfile(dupeTokenHandle, ref profile);
if(retval==false)
{
Console.WriteLine("LoadUserProfile failed. Error code: " + Marshal.GetLastWin32Error());
return;
}
bool loggedOn = LogonUser(
"CustomAppUser", //Username
"AA02", //Computer name
"customappuser", //Passwd (Remember, this is case-sensitive.)
3, //Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
0, //Logon provider = LOGON32_PROVIDER_DEFAULT.
out token //token for the specified user.
);
int ret = GetLastError();
if(ret!=0)
{
Console.WriteLine("Impersonation error. Error code: " + ret.ToString());
return;
}
It seems to me that you don't need to call LoadUserProfile prior to calling LogonUser - am I right? But what else can be the problem?
THanks!
norm
|
|
|
|
|
I got it working now, it was a really stupid mistake. LogonUser returned true!
It was stupid that I invoked GetLastError after LogonUser returned "true" - indicating no error at all.
Thanks anyway.
norm
|
|
|
|
|
I have been tasked with producing an application that will decode SNMP packets. The short story is that this application must capture SNMP trap events sent from various locations and store the results in a database.
Is anybody aware of any tutorials, code samples that step through the decode process?
post.mode.signature = true;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
I'm looking for someone to help me make sense of the results I'm observing
when using the ThreadPool class in a COM-Interop scenario. Here's the set
up:
1) A classic ASP page instantiates and calls MethodA on COM+ Class (C1).
2) MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class
(N1). (Note: N1 has been registered using RegASM and is present in the
GAC).
3) MethodB of .NET class (N1) uses the ThreadPool.QueueUserWorkItem method
to queue up a call to MethodC on .NET Class (N2).
4) MethodC of .NET Class (N2), (called on a ThreadPool thread),
instantiates and calls MethodD on COM+ class (C2).
5) MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class
(C3).
Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2)
to retrieve the results of the "background" processing. These results are
passed back to COM+ Class (C1) and ultimately displayed on the ASP page.
Note: All COM+ classes are registered within the same COM+ application;
and this application is configured as a "Library" application.
I believe this sequence of calls results in the following transitions:
1)An IIS worker thread, (running C1), transitions to .NET managed thread,
(running N1). I'm not at all clear as to what process owns the .NET
thread.
2) As a result of item#1 a .NET ThreadPool thread, (running N2),
transitions to a COM+ thread, (running C2).
3) I'm assuming the same COM+ Thread from item#2 is used to run C3.
4) The COM+ Thread running C2 and C3 completes and transitions back to
the .NET ThreadPool thread running N2.
5) Based on a flag exposed as a static member of N2, the "original" .NET
Thread begins accessing static members of N2. (These static members are
used to aggregate results across multiple ThreadPool threads.)
6) Finally, the "original" .NET thread transitions back to the IIS worker
thread running C1.
After modifying Machine.Config such that the "ProcessModel" tag used
the "system" account instead of the "machine" account, I was able to get
this working in Debug mode. The modification was required to enable
transition #2 (listed above). Prior to making this modification an
exception was thrown indicating an inability to call COM+ class C2. (Sorry,
I don't recall the exact exception.)
When I say Debug mode, I'm referring to running the code within the
VS.NET and VS6 IDEs and stepping between break points.
With everything working in Debug mode, I then attempted to execute the code
without debugging. Based on well placed App.LogEvent and
EventLog.WriteEntry calls, it appears that the following is occurring:
1) All calls prior to the calling of COM+ Class C3 appear to be working.
2) The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant
returned from this call is empty. During successful execution the
resulting variant contains an array with a "UBound" of 5. The real
puzzling thing about this situation is that an error with COM+ class C3
should result in a variant containing an array with a "UBound" of 3.
There should always be an array returned from COM+ C3!
So the questions are as follows:
1) Is it possible that the return values, (which are passed ByRef), aren't
being marshalled properly between COM+ Class C2 and COM+ Class C3?
2) Is it possible that the call from COM+ Class C2 to COM+ Class C3 is
failing silently? (Placing App.LogEvent calls within COM+ Class C3
requires the involvement of another team.)
3) Is there some security or thread related issue here that I'm just not
seeing? And does this underlying issue explain why things work during
Debug and fail when not running under an IDE managed thread?
Thanks for taking the time to read all of that.
|
|
|
|
|
After further review, it appears that my problem was due to an apparent inability to call an in-process STA COM+ class from a MTA "ThreadPool" Thread.
Moving COM+ Class (C2) to an out-of-process "Server" application allowed me to "work-around" my error.
Does anyone know whether it is possible to call in-process COM+ classes from a "ThreadPool" thread?
Thanks!
|
|
|
|
|
Hi, very simple question:
WindowsPrincipal principal = (WindowsPrincipal) Thread.CurrentPrincipal;
bool bIsInRole = principal.IsInRole(WindowsBuiltInRole.Administrator);
What if the role is a user defined role? (ie. not built in)
Thanks.
norm
|
|
|
|
|
How about:
bool isDishWasher = principal.IsInRole("DishWasher");
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Thanks. I got it working now =)
norm
|
|
|
|
|
This may sound stupid ...
Could someone explain the difference between OleDB and ADO? I mean I can use both to access a database so what is the point of having both available ?
Am I right in this?
Cheers
John
|
|
|
|
|
Yes, you are right, you can use both.
ADO is a layer over OLEDB. ADO is easier to use, is fast and it's "universal", meaning that code using ADO (and well written queries) can usually be database independent. ADO achieves this through a lowest common denominator implementation and feature querying. So, most high-level code uses ADO.
OTOH, OLEDB can be used both as a database commnunication driver for ADO and as a substitute for ADO. If you want to use some specific DB features (e.g., some BLOB specific features on Oracle), OLEDB is the way to go. It is slightly faster than ADO (my own biased benchmarks showed less than 5% difference, but YMMV).
But this is a weird question on a C# forum
Help me dominate the world - click this link and my army will grow
|
|
|
|
|
Hi!
I need to use configuration file with subSections.
<Section>
<SubSection>
<Parameter>
<Parameter>
<Parameter>
</SubSection>
</Section>
I use Configuration Application Management Block (CMAB)
that does not support SectionGroup or something like that.
May be someone knows how can I manage this.
Thank you!
|
|
|
|
|