Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi guys,

 

I'm developing some project for synchronizing through the SSL channel. This operation takes long time and when you're running in from web, you don't see the progress, that's why I decided to use threads. All is working fine since is the web interface used only by one user. In the moment when another user runs another synchronization, currently running thread is killed and it starts new one. It seems to me there is problem with assigning of slots for new threads. I don't know how to force to create new threads with new unique ID. I'm using following simple code:

 


       Dim CoreThread As Thread = New Thread(AddressOf SynchroCore)
       CoreThread.Priority = ThreadPriority.Highest
       CoreThread.ApartmentState = ApartmentState.MTA
       CoreThread.Name = Now.ToString
       CoreThread.Start()

 

Please can someone help me?

Thanks a lot

Jarda

 

 

==================

Jaroslav Lhotak

Internet Team

Radio Free Europe / Radio Liberty Inc.

http://www.rferl.org/

  • *Gurus*
Posted
You do not need to assign values to the "Name" or "ApartmentState" properties of any thread object. As a matter of fact using the two properties may be causing the issues you describe. I'd strongly suggest removing assignments to "ApartmentState", since its presence it strictly for COM interoperation.
  • *Gurus*
Posted

A new thread is created with each declaration of a Thread object.

 

The following wil create two threads not two references to the same thread:

 

Dim thread1 As Thread = New Thread(AddressOf Procedure1)
Dim thread1 As Thread = New Thread(AddressOf Procedure1)

 

Of course if the HTTP request is completed before the background thread completes the background thread will never finish processing, as it will be killed. In a case such as this you'll need to block the main thread from exiting until the background thread has finished processing. You can do this using asynchronous locks or the Thread.Join() method.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...