Sign in to follow this  
Lionheartadi

[.net] Events int .NET

Recommended Posts

Lionheartadi    154
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. :)

Share this post


Link to post
Share on other sites
Promit    13246
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.

Share this post


Link to post
Share on other sites
afterburn    124
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.

Share this post


Link to post
Share on other sites
thona    100
::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.

Share this post


Link to post
Share on other sites
Lionheartadi    154
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

Share this post


Link to post
Share on other sites
Troj    138
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
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this