Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Thursday, March 22, 2012

Thread doesnt do anything

I have a Sub called SendMessages() that is supposed to do some database work and send an email message in my web app.

Now if I call it directly, it does what it should. I've now been trying to place this Sub into a thread of its own..

i.e

Dim sendMessageThread as New Thread(AddressOf SendMessages)
sendMessageThread.Start()

But the page ends up doing nothing...

Any ideas?Is your SendMessages sub within the same class or in another class?
Have you stepped through your code to see if the thread is entering the sub?
It is in the same class. I'm not using VS.NET so I can't do any stepping...

The thread is being called from Page_Load()
Post the code.
As far as it seems, the Sub ReceiveMessages is not being called at all!!!
Here is my code

Sub Page_Load()
Dim NewThread As Thread = New Thread(AddressOf ReceiveMessages)

NewThread.Priority = ThreadPriority.Lowest
NewThread.Start()
End Sub

Public Sub ReceiveMessages()
' Code here to connect to pop3 server and loop through messages
End Sub

Thread Issue

I have a method that serves the purpose of FTPing a file. I intend to call that method by a thread. The method I intend to call takes FileSystemEventargs e as a parameter. Please tell me how to do that.

Regards,

Sandeep Kumar

hi,

you could use some similar code:

//// invoke the method using thread//Thread ftpThread =new Thread(new ParameterizedThreadStart(TransferFile));FileSystemEventargs args =new FileSystemEventargs();ftpThread.Start(args);//// this is your method that will be invoked//public static void TransferFile(object fArgs){ FileSystemEventargs args = fArgsas FileSystemEventargs;// // do sth here //}

Cheers,

Yani