473,398 Members | 2,812 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,398 software developers and data experts.

MethodInvoker and ThreadPool


Hello,

I have a problem with thread safe in VB.NET 2005.

I'm calling DLL from EXE file, in separete thread.
That DLL must update some Tables in database.

When I using ThreadPool, i have problem because many thredas update same
Table and I have wrong results :(

When I using MethodInvoker everythong is OK, but maximum thread is 20
(not enough for my projet)

So.. the solution is make ThreadPool safe, or change maximum nuber of
threads when using MethodInvoker, or something else...?

Code:

Private Sub BufferRead(ByVal ar As IAsyncResult)
Dim BytesRead As Integer
Dim Data As String
Try
SyncLock client.GetStream
BytesRead = client.GetStream.EndRead(ar)
End SyncLock
Data = Encoding.ASCII.GetString(readBuffer, 0, BytesRead)
Data = VisakPrimljenogStringa & Data
VisakPrimljenogStringa = ""
If Data.Substring(Data.Length - 1) = "|" Then
Data = Mid(Data, 1, Data.Length - 1)
Else
VisakPrimljenogStringa =
Data.Substring(Data.LastIndexOf("|") + 1)
Data = Data.Substring(0, Data.LastIndexOf("|"))
End If
Dim NizXMLova() As String
NizXMLova = Data.Split("|")
Dim i As Integer
'Dim sms(NizXMLova.Length - 1) As core.SMSPoruka
Try
For i = 0 To NizXMLova.GetUpperBound(0)
Dim sms As core.SMSPoruka
sms = core.SMSPoruka.FromXMLstring(NizXMLova(i))

Dim objniti1 As clsNiti

'Option 1 - Fast, but not safe
objniti1 = New clsNiti(sms, _AjDiOperatera)
ThreadPool.QueueUserWorkItem(New
WaitCallback(AddressOf objniti1.ObradaPoruke))

'Option 2 - Safe, but to slow, and MAXthread=20
Dim NovaNit1 As New MethodInvoker(AddressOf
objniti1.ObradaPoruke)
NovaNit1.DynamicInvoke()

Next i
Catch ex As Exception
End Try
SyncLock client.GetStream
client.GetStream.BeginRead(readBuffer, 0,
READ_BUFFER_SIZE, AddressOf nestostiglo, Nothing)
End SyncLock
Catch e As Exception
End Try
End Sub

Thanks,

Jovo

*** Sent via Developersdex http://www.developersdex.com ***
Jan 23 '08 #1
0 2772

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

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
5
by: Duane Pressley | last post by:
I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: 1.. A classic ASP page instantiates and calls...
6
by: Max Adams | last post by:
Threads and ThreadPool's If I use a ThreadPool how can I tell when a thead in the threadpool has exited? I don't want to set a global member variable I would much rather be able to act on an...
1
by: doudou-shen | last post by:
I will use threadpool do some work with threadpool . but I haven't any information about it . who can help me! thank a lot
13
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled...
10
by: Lenn | last post by:
Hello, I have always used a certain design pattern for multithreaded Windows app; Start new worker thread from UI thread, use events to notify UI threads when something happens, update UI...
4
by: _DD | last post by:
In the switch-over to C# 2.0, I thought it would be good to get rid of external delegates for thread access to controls. In looking into anonymous methods I ran across MethodInvoker. I haven't...
3
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class...
3
by: UltimateBanoffee | last post by:
Hi, I'm using asp.net 2.0 and I have an understanding issue here! I don't quite understand when the available threads in the ThreadPool are ever used. The application I have running doesn't use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.