Solved

How to call a global function from multiple threads in vb net

Posted on 2013-06-18
8
780 Views
Last Modified: 2013-09-27
HI Experts,

I'm using VB net  (Visual Studio 2012)  to program an application that runs several threads.

Each thread needs to send data to a log database.  

I've created a function in a separate module, called SendToDBLog(strMessage), which sends text to the Database via a stored procedure.

Can each of the threads call this function without any issue or will they conflict?

Can my main program call this function without affecting any thread?

If this would cause problems, please explain why and how to do it properly!.

Many thanks Experts!
0
Comment
Question by:jmsjms
  • 4
  • 3
8 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39256587
Even probably you can call your module function without any problem from both your threads and your main program, I think it's even better if you put your function into a class and you create a new instance of the class inside each one of your threads. So, each thread manages its own instance of the class and you're sure that there'll be no conflict.

Hope that helps.
0
 

Author Comment

by:jmsjms
ID: 39261754
So, from a specific thread,  if a call a function on a seperate instance of a class (thats unique to the thread), there would never be a conflict?

THe thread being called from the main routine,  is a sub in a specific instance of a class.  If this thread just called functions in that instance would that stop conflicts too?

Many thanks
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 39261760
If each thread has its own instance of a class, you can safely call all of that class methods/functions without problem... the only problem would be if the functions that you call try to access a shared resource at the same time.
0
 

Author Comment

by:jmsjms
ID: 39261833
Just to clarify then...

Currently I run each thread by calling instance of a class method

i.e.
  myThread(i) = New Threading.Thread(AddressOf WorkClass(i).CollectData)


The CollectData method at the moment calls functions inside the workclass Class and some general fuctions outside.

So if all functions were inside the workclass I dont have to worry about conflcts? (apart from resource clashes)?  

THanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39271621
0
 

Author Comment

by:jmsjms
ID: 39486208
Just catching up on this unfinished question.

Roland - is my thinking right in my comment above
(by: jmsjmsPosted on 2013-06-20 at 10:07:22 ID: 39261833)

Anyone else agree/disagree?

THanks
0
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39486216
I think your comment is right. If anyone disagrees, please explain why.
0
 

Author Closing Comment

by:jmsjms
ID: 39527098
Many thanks  for the info.  Cheers John
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tabcontrol Caption? 1 24
System32Int Error 8 44
VB.NET HttpWebRequest 12 32
Passing a form as a parameter to an external class 1 10
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now