mulit-thread

galaxy2004

Newcomer
Joined
Apr 1, 2005
Messages
6
I have created an application which runs multi-thread procedures.
Thread can be run in the IDE (design mode). When I packaged up the application and installed on the client machine (with Framework 2.0 installed), the thread does not start.
here is the code :
'-------------------------------------------------
Private Delegate Sub Task(ByVal state As Object)

private sub start()
dim tmpStr as string = "Test Message"
Dim worker As New Task(AddressOf RptThread)
worker.BeginInvoke(tmpstr, Nothing, Nothing)
end sub


Private Sub RptThread(ByVal state As Object)
dim txt as string = state.tostring()
MsgBox(txt)
end sub
'----------------------------------

The start() procedure will be fired when a button is clicked.
"Test Message" is supposed to be shown, but nothing shows.
I have VS 2003 and VS 2005 installed on my development machine.

did I miss something when I install the application ?
 
Do you get any errors show or is it literally just failing to display the message box?

Have you tried running it on your development box but without a debugger attached (either running the .exe direct or from VS using the 'Start Without Debugging' option)?

One of the rules of windows forms is that you shouldn't mess with the UI from anything other than the main UI thread - not sure if it is relevant but the call to MsgBox could be falling foul of this rule; it might be worth trying to write to the event log
Visual Basic:
my.Application.Log.WriteEntry(txt)
in the RptThread method to see if that works.
 
No errors show, it just failing to display the message box.
I have tried to use my.application.log.writeEntry(txt) instead of the message box. If I run it in IDE or directly run Exe in the Bin directory, it works fine.
If I run it in the client machine, no log file has been created, i.e. seems like the thread cannot start.
 
Is the .exe installed on the PC in question or are you running it from a network? Also if you run it from your PC but logged on as the user in question does it still work? Similarly if you log onto a user's PC as yourself and run the app does it work?
 
yes, It runs on the pc in questions.
yes, I have tried to log in my ID and run it, But no hope and same problem.

I converted the program from Net.2003, will this causes problem ?

Big headache ! we have some other multi-thread apps waiting to be converted to .Net 2005. I predict that we will run into this kind of trouble seriously.
 
You will always run into this problem, if you don't understand the problem.

In FW 1.1 it was possible, but not advisable, to call the UI-Thread from the workerthread.

In FW 2.0 this is not allowed anymore.
You always have to invoke everything from the workerthread.

If you only do easy things look at the backgroundworker.

Otherwise look into Invoking.
 
Debugging

FZelle, you are correct, but the point of writing to the event log described by PlausiblyDamp was to eliminate cross-thread UI calls as the problem. Assuming this has been done, then there must be some other reason. Besides, although MessageBox.Show does involve UI, I very much doubt UI thread marshalling is required, as a message box is owned by the thread it is created on, which would be the current thread (unlike a form or control). It may not behave as required (i.e. be modal with respect to the rest of the application) but it should still display regardless.

As for the original problem, in your button click event (or wherever Start is called from) do you have any exception-handling code which might be catching and consuming exceptions without reporting them?

As annoying and pointless as it may seem, a good start might be to place multiple logging calls around the problem area of code, like so:

Visual Basic:
Private Delegate Sub Task(ByVal state As Object) 

Private Sub Start()
    My.Application.Log.WriteEntry("Start() entered")

    Dim tmpStr As String = "Test Message"
    Dim worker As New Task(AddressOf RptThread)
    My.Application.Log.WriteEntry("worker created")

    worker.BeginInvoke(tmpstr, Nothing, Nothing)
    My.Application.Log.WriteEntry("worker invoked")
End Sub

Private Sub RptThread(ByVal state As Object)
    My.Application.Log.WriteEntry("RptThread started")
    Dim txt As String = state.ToString()
    MessageBox.Show(txt)
End Sub

You may also want to try other thread-starting approaches, such as ThreadPool.QueueUserWorkItem or creating a Thread object. Again, this may sound like a rather pointless exercise but you will have eliminated certain possible causes of the problem, which is what debugging is all about.

Good luck :cool:
 
Last edited:
Mr.Paul,
It works fine under the IDE, all messages are in log file. But not the client pc, except "RptThread started", all other messages can be written in the log file.
 
Does the client PC have any other .Net software installed that is exhibiting strange behaviours? Also do you know if any changes have been made to the client pc's security policy?
 
I found out the problem.
We have a Crystal Report object in the main class. We have to put the CR merge module in the setup project for distribution,i.e. the installation package.
That's why the program runs well in IDE (all CR dlls are already installed), but not on the client machine.
just curious, why there is no error message telling what causes this when running the program on client machine ?! but just ignored the procedure.

Thank all of you
 
Back
Top