473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Event handlers are not threads?

Dear all,
I do need to lock a not thread-safe object from multiple access. This object
is accessed in OnPaint,MouseMove,MouseUp,MouseDown.
SyncLock seems to not work(?) because event hadlers are not
threads(?).Please give me solution advice.
Thanks in advance.
Boni
Nov 21 '05 #1
3 1136
Windows messages are received and dispatched from the main UI thread so
typically you do not have multithreading problems unless your application is
calling these methods directly from a different thread. If so, you need to
be sure to use Control.Invoke and pass a delegate instead of calling the
methods directly. Control.Invoke will marshall all of your calls to the main
UI thread instead of from your worker thread.

"Boni" wrote:
Dear all,
I do need to lock a not thread-safe object from multiple access. This object
is accessed in OnPaint,MouseMove,MouseUp,MouseDown.
SyncLock seems to not work(?) because event hadlers are not
threads(?).Please give me solution advice.
Thanks in advance.
Boni

Nov 21 '05 #2
Dear John,
unfortunately the multithreading problems do happen. I see that MouseMove
call overlapes with OnPaint call of the same control.
Sometimes mousemove is not finished where OnPaint is already started.
Is there any solution for that?
Thanks in advance,
Boni
"TrtnJohn" <Tr******@discussions.microsoft.com> schrieb im Newsbeitrag
news:32**********************************@microsof t.com...
Windows messages are received and dispatched from the main UI thread so
typically you do not have multithreading problems unless your application
is
calling these methods directly from a different thread. If so, you need
to
be sure to use Control.Invoke and pass a delegate instead of calling the
methods directly. Control.Invoke will marshall all of your calls to the
main
UI thread instead of from your worker thread.

"Boni" wrote:
Dear all,
I do need to lock a not thread-safe object from multiple access. This
object
is accessed in OnPaint,MouseMove,MouseUp,MouseDown.
SyncLock seems to not work(?) because event hadlers are not
threads(?).Please give me solution advice.
Thanks in advance.
Boni

Nov 21 '05 #3
The only way this can happen is if you, or some other logic, gives control
back to the message pump by calling Application.DoEvents. But, this still
occurs on a single thread. Each message is processed completely unless it
gives up control using DoEvents. That is why when you use DoEvents you need
to be careful because you can have re-entrancy problem. You need to add your
own state control in your application to manage this.

"Boni" wrote:
Dear John,
unfortunately the multithreading problems do happen. I see that MouseMove
call overlapes with OnPaint call of the same control.
Sometimes mousemove is not finished where OnPaint is already started.
Is there any solution for that?
Thanks in advance,
Boni
"TrtnJohn" <Tr******@discussions.microsoft.com> schrieb im Newsbeitrag
news:32**********************************@microsof t.com...
Windows messages are received and dispatched from the main UI thread so
typically you do not have multithreading problems unless your application
is
calling these methods directly from a different thread. If so, you need
to
be sure to use Control.Invoke and pass a delegate instead of calling the
methods directly. Control.Invoke will marshall all of your calls to the
main
UI thread instead of from your worker thread.

"Boni" wrote:
Dear all,
I do need to lock a not thread-safe object from multiple access. This
object
is accessed in OnPaint,MouseMove,MouseUp,MouseDown.
SyncLock seems to not work(?) because event hadlers are not
threads(?).Please give me solution advice.
Thanks in advance.
Boni


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
6
by: Amir Hardon | last post by:
I am dynamically adding rows to a table, and each row have a button which removes it. I have successfully implemented this for mozilla but I'm having troubles with IE, here is how I did it: ...
1
by: Jerry J | last post by:
I'm trying to understand how many threads are involved when a client event handler is called. I am using a simple .net windows application. I click a button on a form that triggers an event. ...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
6
by: Luke Matuszewski | last post by:
As in topic... has anyone used it ? I tried to use it but i guess i failed... here is a code: <html> <head> <title></title> <script type="text/javascript"> function closedWin() {...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
9
by: cmwb2000 | last post by:
I am trying to build a peice of software to survey how a user interacts with a pc. I need to record keystroke latencies and durations etc. I have got the event handler working and I was wanting to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.