473,320 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,320 software developers and data experts.

Thread crossing

Hello,
I created an application with the FrameWork 1.1 containing differents
forms and threads runing. There was no problem, I could click on a picture
on my Main Form to call the Show() function of another form without problem.

Then I installed Visual Studio 2005 and the FrameWork 2.0. I launched my
application and I had lots of error saying I was crossing the thread calls
when clicking on the picture of my Main Form or calling the BeginInit()
function of a custom control containing a TreeView.

I read the MSDN and found the
System.Windows.Forms.CheckForIllegalCrossThreadCal ls parameter and set it to
false. It is now working but I know that it is just a trick hiding some
mistakes in my source code.

My question is: do I have to create delegates each time I want to use a
function of a form or a control from another form or thread ? If I want to
call the Show() function of a form from my Main Form, do I have to create on
the child form a delegate and a new NewShow() function like this (for
example):

public classe MyForm : System.Windows.Forms.Form
{
private delegate void show(void);

public void NewShow()
{
if (this.InvokeRequired)
{
this.Invoke(new show(base.Show(void)));
}
else
{
base.Show();
}
}
}

It is just an example, the syntaxe may be incorrect but the idea is
here. Prehaps did I miss something and I hope someone will be able to help
me !

Thank you

Laurent
Sep 19 '06 #1
2 2327

"Laurent Navarro" <yo*@yop.comwrote in message
news:uh**************@TK2MSFTNGP03.phx.gbl...
| Hello,
|
|
| I created an application with the FrameWork 1.1 containing differents
| forms and threads runing. There was no problem, I could click on a picture
| on my Main Form to call the Show() function of another form without
problem.
|
| Then I installed Visual Studio 2005 and the FrameWork 2.0. I launched
my
| application and I had lots of error saying I was crossing the thread calls
| when clicking on the picture of my Main Form or calling the BeginInit()
| function of a custom control containing a TreeView.
|
| I read the MSDN and found the
| System.Windows.Forms.CheckForIllegalCrossThreadCal ls parameter and set it
to
| false. It is now working but I know that it is just a trick hiding some
| mistakes in my source code.
|
| My question is: do I have to create delegates each time I want to use a
| function of a form or a control from another form or thread ? If I want to
| call the Show() function of a form from my Main Form, do I have to create
on
| the child form a delegate and a new NewShow() function like this (for
| example):
|
| public classe MyForm : System.Windows.Forms.Form
| {
| private delegate void show(void);
|
| public void NewShow()
| {
| if (this.InvokeRequired)
| {
| this.Invoke(new show(base.Show(void)));
| }
| else
| {
| base.Show();
| }
| }
| }
|
| It is just an example, the syntaxe may be incorrect but the idea is
| here. Prehaps did I miss something and I hope someone will be able to help
| me !
|
| Thank you
|
| Laurent
|
|

That means your application was buggy from the start, you should never touch
the UI from another thread than the creator of the UI elements (form,
controls). The V2 framework implements a debug probe to watch for this
common error.
This means that you need to call Control.Invoke or BeginInvoke whenever you
need to touch (update or read a property) from another thread.

Willy.
Sep 19 '06 #2

Willy Denoyette [MVP] wrote:
>
That means your application was buggy from the start, you should never touch
the UI from another thread than the creator of the UI elements (form,
controls). The V2 framework implements a debug probe to watch for this
common error.
This means that you need to call Control.Invoke or BeginInvoke whenever you
need to touch (update or read a property) from another thread.
I think I find the bug of my application by this advice. Very useful
though

Sep 19 '06 #3

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

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
4
by: Daylor | last post by:
in win32 process , when u create new process,u have new main thread. i know,appDomain r logical procces,that exists in 1 win32 process. the q: is there way to create second appDomain (the...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
39
by: elnanni | last post by:
I've a problem in the use of threads, they don't work as i want them to. Here's the code, the problem is that if i uncomment the //pthread_join(thread_ID, NULL);, the main program stops until the...
0
by: shantanuaggarwal | last post by:
Hi, My scenario is as follows: I have an application, in which in one component, I am calling a method in a different thread. Please note that this method will load a dynamic assembly. Now...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.