[.net] Events int .NET

Started by
4 comments, last by Troj 19 years, 8 months ago
Hi I am wondering is there a way that you can alter events in .NET and to be more spefic event raised by a form, component(control). It's just that events kind of "hijacks" your code processing order. What I mean by this is that when a event occurs your code that was beeing processed will be halted and the .NET processes the event itself then when that is over it goes back to that line of your code where the event was raised. Now ofcourse the events are suppoused to work like this, but I would much more prefer event to be handled as the first thing in the next loop of the program or the form etc... Like Win32 messages and/or MFC... And I'v had even more problems when a program built to take advantage of threading/multi-threading. I kind of goes a little out of control at that moment. Up untill now just by changind the order or your code helps somehow, but still it causes me some dilemas and extra code sometimes. So if anyone knows how to get more control over events I would be most gratefull. Ou I have only worked with MC++, but I gues same things apply to other .NET CLS based languages. Well correct and/or enlighten me on this matter. :)
Adrian Simionescu
Advertisement
If you use Application.Run(), events will be processed one by one. If you don't, then events can't be processed unless you call Application.DoEvents().

How is your code being hijacked by events? An event may occur, but the actual call can't happen until your application processes the message.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Events will be processed when the thread state is returned to the loop. So if an event of pressing a button causes processing of a file. while the file is being processed another event occurs then the event will be held in the queue until the thread resumes to remove the item off the queue.

In multi-threading you would have to sync the threads with Monitor class or some other means to transfer data between them. A thread will not halt to process an event.
--What are you nutz?I have nothing to say to your unevolved little brain. The more I say gives you more weapons to ask stupid questions.
::It's just that events kind of "hijacks" your code processing
::order. What I mean by this is that when a event occurs your
::code that was beeing processed will be halted and the .NET
::processes the event itself then when that is over it goes back
::to that line of your code where the event was raised.

I will quote Charles Babbage.

::I am not able rightly to apprehend the kind of confusion of
::ideas that could provoke such a question.

Your statment quoted from me is just one thing: totally plain wrong.

Go back and read the documentation again.
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)
Quote:Original post by Promit
If you use Application.Run(), events will be processed one by one. If you don't, then events can't be processed unless you call Application.DoEvents().

How is your code being hijacked by events? An event may occur, but the actual call can't happen until your application processes the message.


Hmm.. thanks Promit I think this will help. I'll have to do some minor changes in the code, but I think this will help. Also thank to Afterburn, you info was also helpfull
Adrian Simionescu
It's not for the faint hearted but if you must make sure your Program handles messages before something else does you can add this to your main program


protected override void WndProc(ref Message m)
{
// Handle your windows messsages here
// Its a good place to handle Keyboard events too
// but know your Win_32 Messages, and dont make this too complicated
// else your will slow everything down


base.WndProc(ref m); // <-- I am very important
}

This topic is closed to new replies.

Advertisement