|
Cool, hosamaly!
You are so knowledgeable!
regards,
George
|
|
|
|
|
The added benefit of:
MyObject obj = (genericObject as MyObject);
over
MyObject obj = (MyObject)genericObject;
is that the first example won't throw an exception if it can't cast it, it'll set <c>obj to <c>null rather than throw an <c>InvalidCastException
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
hello
System.Double (.NET/CLR type) vs double (C# type)
My question is, when to use what?
Thanks!
dev
|
|
|
|
|
They are the same thing.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
The C# double type is just an alias for System.Double . Just like int is an alias for System.Int32 .
|
|
|
|
|
Hello,
I am just learning LINQ to SQL and so far I am excited and I am going to replace DataSet usages in my application with DBML (LINQ to SQL). Now, I am thinking about a scenario when I will change the structure of the table in my SQL server, how will my LINQ queries be updated in my code ? Will they be auto updated or I will have to do it manually in all files. If so, then what is the efficient solution for using LINQ when I have a plan to change the Database table structures !!
Regards
|
|
|
|
|
Don't change the table structure?
No mapping tool is going to automatically fix your code if you significantly change the database design. I'd suggest you consider designing your database first, then coding.
|
|
|
|
|
Hello sir,
Thanks for your reply.
As you would realize that, in future, I may need to add an extra field in a table or I may need to delete a field from a table. I think, the nature of this requirement is common to every developers, not only me. So, what is the efficient procedure to handle this situation in the future ?
One benefit of using DataSet that I was enjoying... When I changed a field in my database, I updated the dataset and as all table adapter methods stay together in the datase, I can easily track the usage of the methods in my code and fix accordingly. But when I am using DBML file, I dont see any methods (unless SPROC) in the DBML file, so I wont have any idea about how many files are using the table from the DBML. Thats why, I was wondering and thinking that, there must be a way.
|
|
|
|
|
hello,
I'm testing .NET connection pooling facility, I configured max pool size 10 and in accordance there was no exception when I oConn.Open until I opened the 11th connection.
<br />
static void Main()<br />
{<br />
string strConn = "Data Source=DEV\\SQLEXPRESS;Initial Catalog=Northwind;Persist Security Info=True;User ID=NorthwindSA;Password=xxxxx;connection reset=false;connection lifetime=5;min pool size=5;max pool size=10";<br />
<br />
IDbConnection oConn = null;<br />
ArrayList oConnections = new ArrayList();<br />
int nIndex = 0;<br />
<br />
for (int i = 0; i < 20; i++)<br />
{<br />
try<br />
{<br />
oConn = new SqlConnection(strConn);<br />
oConn.Open();<br />
oConnections.Add(oConn);<br />
<br />
Thread.Sleep(100);<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine("iteration: " + i + ", " + ex.Message);<br />
nIndex = i;<br />
break;<br />
}<br />
finally<br />
{<br />
<br />
}<br />
}<br />
<br />
Console.WriteLine("max number connection established: " + nIndex + ", preparing to dispose connections openned");<br />
<br />
foreach (IDbConnection oConn2 in oConnections)<br />
{<br />
if (oConn2 != null)<br />
{<br />
try<br />
{<br />
oConn2.Close();<br />
}<br />
finally { }<br />
}<br />
}<br />
oConnections.Clear();<br />
<br />
return;<br />
}<br />
However - one thing I am not sure is - I'm watching Perfmon \ SQL Server General Statistics \ User Connections. The counter is showing "3" before and after test. The fact that my test application fires up 10 new connections (min=5,max=10) does not seems to have anything to do with Perfmon counter.
Thanks
dev
|
|
|
|
|
Trying doing a query with each of the connections as see what happens.
Also, the PerfMon counter you're using is looking at the connections inside SQL Server. It's not looking at them from your code's point of view.
You might find it interesting to look at both sides at the same time. Start looking at the .NET Data Provider for SQL Server counters.
|
|
|
|
|
I am trying to correlate oConn.Open with Perfmon counter...
dev
|
|
|
|
|
And ....?? My answer doesn't change.
|
|
|
|
|
I think it nonsense if some application can access parallel port without additional driver
but I must provide own driver. After attach an "dll viewer" to "portmon", I found exported function
called _inp and _outp inside msvcrt.dll or msvcr80.dll. It looks like same with _inp and _outp
function on turbo c++ compiler. When I try to call with
[DllImport("msvcrt.dll",EntryPoint = "_outp")]
public static void OutP(int address, int value);
there's no exception occurs, but my application always shutted down with errors.
Is someone there know what signature of "_outp" is? or know whats wrong with my program?
(my program just have two textboxes to input address and value and one button to execute)
No one can prevent me to learn something
|
|
|
|
|
hello
This article[^] tells me it's possible thread aborted before created file is assigned to variable "w" by looking at IL - I examined IL but not sure how we can arrive at that conclusion:
<br />
Aborting pure .NET code is less problematic, as long as try/finally blocks or using statements are incorporated to ensure proper cleanup takes place should a ThreadAbortException be thrown. However, even then, one can still be vulnerable to nasty surprises. For example, consider the following:<br />
<br />
using (StreamWriter w = File.CreateText ("myfile.txt"))<br />
<br />
w.Write ("Abort-Safe?");<br />
<br />
C#'s using statement is simply a syntactic shortcut, which in this case expands to the following:<br />
<br />
StreamWriter w;<br />
<br />
w = File.CreateText ("myfile.txt");<br />
<br />
try { w.Write ("Abort-Safe"); }<br />
<br />
finally { w.Dispose(); } <br />
<br />
It's possible for an Abort to fire after the StreamWriter is created, but before the try block begins. In fact, by digging into the IL, one can see that it's also possible for it to fire in between the StreamWriter being created and assigned to w:<br />
<br />
IL_0001: ldstr "myfile.txt"<br />
<br />
IL_0006: call class [mscorlib]System.IO.StreamWriter<br />
<br />
[mscorlib]System.IO.File::CreateText(string)<br />
<br />
IL_000b: stloc.0<br />
<br />
.try<br />
<br />
{<br />
<br />
...<br />
<br />
Either way, the Dispose method in the finally block is circumvented, resulting in an abandoned open file handle – preventing any subsequent attempts to create myfile.txt until the application domain ends.<br />
I can't see where in IL the variable "w" get assigned the created file stream writer.
devy
|
|
|
|
|
Here:
IL_000b: stloc.0
The reference to the stream writer is the return value of the call on the previous line, so that is what's in the accumulator.
The variable w is the first variable in the method, so that is allocated at position 0 in the stack frame.
The instruction stloc.0 stores the value of the accumulator at location 0.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks
Sounds like to understand this I need to know assembly and IL ...
devy
|
|
|
|
|
Not at all. You only have to realise that calling a method and assigning the result to a variable are two separate operations, so the thread can be aborted between those operations.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thanks
think i understand that - that create file stream and assigning it to variable "w" is not atomic and is indeed two-step operation.
But I wish I could read assembly and IL so I can ildasm then check on things myself.
devy
|
|
|
|
|
hi
how can i send bit's to usb in c# ?
thank's
|
|
|
|
|
There's nothing built in to C# to support this, you'd need to find a library you can consume to do that.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
can i get some direction ? i dont know from where to start ?
|
|
|
|
|
|
Hi,
years ago, when PC interfaces where just serial port and parallel port, it made sense to talk to the port, and make it send and receive the bits and bytes the peripheral manual told you to send and receive in order to operate some peripheral.
Nowadays you should focus on the peripheral device, and not on the interface or cable that is used. So your program should not address the USB bus, it should address the PC driver that goes with the peripheral. A commercial peripheral comes with such a driver; also microcontrollers and other electronics typically come with the drivers required to connect them to a PC. If your vendor cannot offer a driver, you have two choices: change product and vendor, or start developing your own driver (a major effort).
BTW: if your USB is used as an intermediate interface, the same applies. So USB-to-serial cables,
USB-to-parallel cables, USB-to-Ethernet cables, all have their own drivers, and you can forget the USB aspect of them alltogether: the serial port/parallel port/Ethernet will behave almost like its twin on the motherboard. And Vista has most of these drivers built-in too.
|
|
|
|
|
A very good and solid answer!
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hey.
I'm currently hijacking the WM_NCCALCSIZE function to define a custom caption and border areas.
But i'm having an issue with the form constantly resizing itself.
When I maximise the form, it fills the screen like I want it to, but when I restore it back, it's height and width properties are decreased.
I know where in the code it's happening, but I don't know how to stop it from constantly reducing in size, but rather maintain it's original size and simply "append" the non-client area. Any help would be appreciated
Here's the function for the WM_NCCALCSIZE calculations:
protected void WndNCCalcSize(ref Message m)
{
NativeMethods.NCCALCSIZE_PARAMS para = new NativeMethods.NCCALCSIZE_PARAMS();
NativeMethods.RECT winRect;
if (m.WParam == IntPtr.Zero)
winRect = (NativeMethods.RECT)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));
else
{
para = (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
winRect = para.rgrc0;
}
IntPtr HDC = NativeMethods.GetWindowDC(this.Handle);
winRect.Top = winRect.Top + CaptionHeight;
winRect.Bottom = winRect.Bottom - 3;
winRect.Left = winRect.Left + 2;
winRect.Right = winRect.Right - 2;
this.BRect = winRect;
if (m.WParam == IntPtr.Zero)
Marshal.StructureToPtr(winRect, m.LParam, false);
else
{
para.rgrc0 = winRect;
Marshal.StructureToPtr(para, m.LParam, false);
}
NativeMethods.ReleaseDC(this.Handle, HDC);
m.Result = new IntPtr(NativeMethods.WVR_REDRAW);
base.WndProc(ref m);
}
Thanks.
|
|
|
|