472,787 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Shut down thread - thread closes form, form doesn't close because thread calls it etc...


Some thread confusion to lighten up your day:

I have a worker thread and a main form. When the user clicks the Close icon
in the top right of the form, my program tells the thread to "stop". The
thread will then complete its current operation and "Invoke" a method on the
form telling it it has completed. The completed handler then calls Me.Close
(). The trouble is, I seem to have some deadlock here - I mean after I call
Me.Close(), does the form exit the method, return to the thread etc.?

How exactly can a worker thread shut down the form that created it!???

Any ideas?
Cheers
Robin
Nov 20 '05 #1
4 1620
Its ok, nobody panic. I solved this one with an asynchronous call to the
main thread and a bit of fiddling about :)

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:bm*******************@news.demon.co.uk...

Some thread confusion to lighten up your day:

I have a worker thread and a main form. When the user clicks the Close icon in the top right of the form, my program tells the thread to "stop". The
thread will then complete its current operation and "Invoke" a method on the form telling it it has completed. The completed handler then calls Me.Close (). The trouble is, I seem to have some deadlock here - I mean after I call Me.Close(), does the form exit the method, return to the thread etc.?

How exactly can a worker thread shut down the form that created it!???

Any ideas?
Cheers
Robin

Nov 20 '05 #2
Hi Robin,

Praise be that you've solved it!!. My heart's been pounding and my face
has been flushed and my mind's been all of a dither. I can calm down now!!
Aaaaahh. ;-))

Regards,
Fergus
Nov 20 '05 #3
Hi Fergus,

Can you point me to a tutorial that will allow me to share controls among
threads? I am able to do datasets and such as long as I dont use them in the
primary thread but I would like to learn how to use controls otherwise if I
can.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Robin,

Praise be that you've solved it!!. My heart's been pounding and my face has been flushed and my mind's been all of a dither. I can calm down now!!
Aaaaahh. ;-))

Regards,
Fergus

Nov 20 '05 #4
You just need to use Delegate and the controls "Invoke" method. This will
ensure that the control method is executed on the controls thread, not the
thread making the call. Like this:

Here is a delegate, representing a method on my main form (doesn't matter
what it is, could be anything really) - this delegate is defined in my
thread.

Private Delegate Sub _onBeginNodeOperations_Delegate(ByVal nAdding As
Integer, ByVal OperationType _
As OperationsThreadState.NodeOperations, ByVal bIsUndoRedo As
Boolean)

Now, the thread wants to execute the delegate method on the main form
thread, not the current thread, so:

Try

m_Form.Invoke(New _onBeginNodeOperations_Delegate(AddressOf
m_Form.BeginNodeOperations), Parameters)

Catch ex As Exception

End Try
"scorpion53061" <sc************@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
Hi Fergus,

Can you point me to a tutorial that will allow me to share controls among
threads? I am able to do datasets and such as long as I dont use them in the primary thread but I would like to learn how to use controls otherwise if I can.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Robin,

Praise be that you've solved it!!. My heart's been pounding and my

face
has been flushed and my mind's been all of a dither. I can calm down now!! Aaaaahh. ;-))

Regards,
Fergus


Nov 20 '05 #5

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

Similar topics

1
by: jdph40 | last post by:
I am using Access 2002. I downloaded the forms sample database FrmSmp97.mdb from Microsoft and used the following code in the timer event of a hidden form in order to close a database if no...
8
by: Tim Bücker | last post by:
Following scenario: The user opens a form, a thread is started to play a sound ... public void playSoundUsingThread() { if (File.Exists(fileLocation)) PlaySound(fileLocation, 0, 0); //...
4
by: Claire | last post by:
Running XP pro, SP2. Visual studio .NET 2003. App written in C# I have written an application that hides itself when run and shows a notification icon in the system tray. If the main form is...
2
by: MuZZy | last post by:
HI, As i posted below i have an app with a separate thread listening for a tcp client connection. In the simplest way it looks like: void ListenerThreadFunction() { TcpListener l = new...
1
by: mikelostcause | last post by:
Is there anyway to hold the base.WndProc(ref m) until after the Logout() function finishes loading a webpage?? I'm working on shutting down an app that runs in the system tray, I have no...
4
by: pamelafluente | last post by:
Hi Guys, I have a small application which uses a NotifyIcon. The user can set a flag (PreventClosing ) so that when he clicks on the form-cancel button "X", the program will instead be...
23
by: Chukkalove | last post by:
Im sorry, I dont know the correct description for a hierarchy of parent and child forms. I have a main form that opens a child form modally. This child form in turn opens it's own child form...
1
by: TC | last post by:
I'm confused about the proper way to shut down my application. I have a form which instantiates a control, which instantiates another control, which instantiates yet another control that runs a...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.