|
Sorry I have no link at hand but when reading such things I just have to rant about it.
|
|
|
|
|
A race condition can occur when an event is fired incorrectly. It has nothing to do with how handlers are subscribed and unsubscribed. If you fire like this:
public event EventHandler HandleThis;
void OnHandleThis(EventArgs e)
{
if (HandleThis != null)
{
HandleThis(this, e);
}
}
A separate thread could unsubscribe the last handler from the HandleThis event between the time you check for null and the time you actually fire it.
You can eliminate the race condition by using a temporary variable.
void OnHandleThis(EventArgs e)
{
EventHandler handler = HandleThis;
if (handler != null)
{
handler(this, e);
}
}
This page[^] mentions the problem and the solution. It's for WinFX, not v1.1, but it's the same concept.
I'm not sure why your supplier thinks you should handle events you're not interested in, but he's wrong.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Gizz quoted his supplier: You should only ever add/remove an event handler once in most applications. It is not designed by Microsoft to have event handlers added and removed continuously as a method to controlling these things.
Well, I don't know about adding/removing event handlers "continuously," but I see nothing wrong with changing event handlers more than once. I've been exploring flow-based programming lately and have been experimenting with using events/delegates as a means of realizing it.
So I have no problem with adding/removing event handlers several times during the lifetime of an application as a means of controlling the flow of a program (or whatever). In fact, I think it's a pretty cool approach.
Gizz continued to quote his supplier: This is because an event handler is usually dealt with in another thread (or how else could it be generated for the application)
If you're receiving event notifications from another thread, then thread-safety is an issue to be concerned about. but that has nothing to do with this:
and adding/removing notifications to the other thread can easily be the subject of racetrack timing errors.
Adding and removing event handlers to an event is thread safe.
When compiling a field-like event, the compiler automatically creates storage to hold the delegate and creates accessors for the event that add or remove event handlers to the delegate field. To be thread-safe, the addition or removal operations are done while holding the lock on the containing object for an instance event or the type object for a static event.
The C# Programming Language - 10.7.1
As far as firing an event, see Charlie Williams' reponse. There is a thread safety issue there.
-- modified at 15:10 Monday 21st November, 2005
|
|
|
|
|
How to get embedded .jpeg from excel worksheet from C#?
|
|
|
|
|
Hi Guys,
I'm using a borderless form (BorderStyle = None)
In the form I have used 3 PictureBoxes as 'Minimize', 'Maximize/Restore', and 'Close' buttons.
I've done the coding in C# and the buttons are working perfectly.
However I couldn't minimize, maximize the form from the taskbar.
As for the Forms with borders it is possible to minimize and maximize the form when you click the title bar from the taskbar.
How can I achieve the same functionality in a borderless from.
Thank you.
|
|
|
|
|
Hello all,
I have an ASP.NET app (using C#.NET) that allows a user to upload a file, and then the program should parse certain info out of the file and insert it into a database. The file is a Word document, so when I try to just use a FileStream, there is so much junk in the file. Do you know of a good way to READ in a Word document without that document being converted into another format from the user?
-- modified at 0:02 Tuesday 22nd November, 2005
|
|
|
|
|
A way of using poiner types in .Net is the IntPtr class. Check MSDN[^] for more help.
I hope you understand...because is a rough world out there...
|
|
|
|
|
Hi Everyone,
How to use C# to call a traditional unmanaged C++ DLL which has many functions with pointer parameters?
For example,
[DllImport("FlyCAMm1_CF.dll", EntryPoint="Capture_A_Frame")]
public static extern bool Capture_A_Frame(LPBYTE pretBuff, DWORD *pdSize);
Thanks.
Tsung-Yu
|
|
|
|
|
Did you ever get an answer to this question Tsung-Yu?
I'm struggling with exactly this issue. It looks like you are using FlyCAMm1_CF.dll, not FlyCAMm1_AV.dll, how did you manage to get an entry point to this DLL? I know they exist, as I've done a dumpbin on the file.
Really hope you can help.
|
|
|
|
|
Hi
I have just created a windows application and when I hit the F1 key to bring up the .chm help i get the 'error' page and nothing can be viewed in my help file.
I know that winXP SP2 fixed some security issues with .chm files but how does anyone get the .chm to display when being called from the help provider using the F1 key? Is there a setting that can be changed?Anything?Anyone?
I am storing the help in a sub directory under the main application.
Thanks in advance.
Stephen
|
|
|
|
|
how to download or upload a file using C#.what is the code for it.I need to download or upload it from a remote server and my local computer
-- modified at 23:49 Sunday 20th November, 2005
|
|
|
|
|
Depends how how/where you want to download/upload it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Dear all,
The function System.Windows.Forms.Control.GetChildAtPoint(Point pt)
find control reference to the Control's Client Rectangle.
However, I am looking for a Control that is out of screen.
i.e. out of the Client Rectangle, but within the Display Rectangle.
Is there any method for me to get that Control by a Coordinate point?
Many Thanks.
|
|
|
|
|
Hi,
How can I make a subclass not inherit its parent class method (not by
private keyword),
but the parent class method need to be with public keyword, coz
it allow other to access it ?
Thanks
|
|
|
|
|
you can do this
public new void myMethod();
That hides the base method and replaces it with a new method on the child.
You can't make a child class not impliment a method that is public on the base class, and doing so would make no sense at all. Even if you impliment the method via an interface, you will inherit it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You can't prevent the method from being inherited by the derived class, but if that method is virtual, you can prevent it from being overridden in the derived class by using the sealed[^] keyword.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi, currently i have a problem creating a print icon in the OWC11 toolbar
i have refer to the msdn article to allow my C# application to handle the events from the web components.
Is there anyway i can do it?
If so , how do i use the web component toolbar delegate in my winform?
Is there any C# reference for web components?
cant seem to get any from the web.
Please give me your guidance
|
|
|
|
|
G'day folks,
With regards to impersonation is it possible to impersonate a low privileged user with administrator privileges programmatically? Most articles I have come across requires you to explicitly define the username, password and domain you are trying to impersonate. I would very much appreciate it if someone could shed some light on this issue.
cheers
V
|
|
|
|
|
anyways i found an article that proved helpful to resolve my problem. here are couple of articles if anyone else gets stuck on this type of issue in the future.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/entserv.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000023.asp
cheers
|
|
|
|
|
I am being driven mad trying to replace a path name in a string - trying to change an absolute to relative link in HTML code
An excerpt of the HTML is below
_________________________________________________________________________________________
\r\nForest Heights "
______________________________________________________________________________________
I have successfully extracted the filename (C:\\htmlexport\\test_files\\img0.png) and used it to copy and rename the file, but all attempts to change the string in this excerpt using code like
string absolutefile;<br />
absolutefile=htmlEditorControl1.BodyHtml.Substring(startind-1,endind-startind+5);<br />
string fname=Path.GetFileName(absolutefile); <br />
string ftype=Path.GetExtension(absolutefile);<br />
string newdest =@fname;<br />
File.Copy(absolutefile,newdest,true);<br />
<br />
returnstring=htmlEditorControl1.BodyHtml;<br />
returnstring.Replace(@absolutefile,@fname);<br />
fails with no change to the string.
Does anyone have any experience with the "escaped" value substitution in a string ?
Thanks
-- modified at 21:12 Sunday 20th November, 2005
|
|
|
|
|
Reanalyse wrote: returnstring.Replace(@absolutefile,@fname);
I don't know if it's a copy/paste error, but strings are immutable, so Replace doesn't actually doesn't modify the string, instead, it returns a new string with the replacements.
returnstring = returnstring.Replace(...)
should work fine.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello once again frends!
Right now im stuck doing a web form in which i have to compare 2 datagrids and/or 2 dates from a database depending on the problem.
now my questions are:
1. how do i compare 2 different dates with each other? i've tried
if (Convert.ToDateTime(ds.Tables[0].Rows[0][1].ToString()).Date >= Convert.ToDateTime(deductDate_1stMonth_End).Date)
{
drNewRow[0] = "S";
}
where ds = the dataset that i queried the dates to be compared from a database. somehow the dataset always return a "null" value in debug mode...i just dont get it.
2. how do i reference the results of datagrid1 in which if it is "null" or "" i place "NE" on the coresponding column of datagrid2? this one honestly i haven't tried yet though i was thinking instead of referencing datagrid1 i probably could go straight to my database query and return my desired result if it shows "null" or "NE". then again i could be wrong...
please oh wise gurus of codeproject could you please assist me in my dilema that i may learn from my mistakes and enhance my skils close to urs
thanx again for all your posts. its greatly appreciated!
Aim small, miss small...
|
|
|
|
|
DateTime.Compare
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
well that was short ...thanx!!
Aim small, miss small...
|
|
|
|
|
Somebody can help me how to use C#
to open tsk file or exact the tdywater.001
|
|
|
|