473,387 Members | 1,798 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,387 software developers and data experts.

Subs in separate threads

116 64KB
Hi,

I have an application that needs to run subs simultaneously - possibly 2 or 3 instances at a time - which might take a few seconds to process. The Sub requires variables so it cannot be a straightforward thread request.

I'm not sure a backgroundWorker is the answer since I think it needs to finish running before it can be run again?

I found some code that uses threads but it completely crashes the entire application which shuts itself down. The application imports System.Threading etc.

The code used to run the sub is as follows.

Expand|Select|Wrap|Line Numbers
  1. Dim mySub As New Thread(DirectCast(Sub() processVal(thisval), ThreadStart))
  2. mySub.Start()
  3.  
The sub processVal runs some calcs and requests data from a 3rd party site.

Are there some extra requirements, imports etc that I should be aware of when using this type of threading procedure? Or a better way to have simultaneous subs running?

Thanks

EDIT: Is there maybe some kind of Async method to do this?
Nov 6 '14 #1

✓ answered by robertybob

ok - so the crash and cross-threading is ok but would still be good to know if there's a simple Async solution

3 1128
robertybob
116 64KB
Managed to stop the crash by adding the line

Expand|Select|Wrap|Line Numbers
  1. mySub.SetApartmentState(ApartmentState.STA)
  2.  
however now have cross-threading issues so will have a look at that.
Nov 7 '14 #2
robertybob
116 64KB
ok - so the crash and cross-threading is ok but would still be good to know if there's a simple Async solution
Nov 7 '14 #3
Frinavale
9,735 Expert Mod 8TB
Will this MSDN article help you: Calling Synchronous Methods Asynchronously?
Nov 7 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: LM | last post by:
Hi, Assume I have a java.awt.Frame running in my main Thread. This frame is the main UI for my application. Is it possible for this application to create a second frame in a completely separate...
0
by: Rod Stephenson | last post by:
I am developing an engineering application for modelling multiphase flows in large pipe networks, and have just discovered the joy of pyopengl for 3D visualization. However the incantation I'm...
1
by: Piotrek Stachowicz | last post by:
Hello, I 've just written a simple c# application and out of curiosity I decided to examine it with spy++. It was a bit surprising, that under my app name in the list of processes, I could find a...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
2
by: Shahid Siddiqui | last post by:
I want to know that whether the asp.net pages are served through separate threads or separate processes?
8
by: Angel | last post by:
Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but I do not seem to find many things about threads and ASP.NET. I have an object(Object 1) which need some...
11
by: Charles Law | last post by:
I know I have brought this one up before, but I didn't get an answer last time, so hopefully I will have better luck this time. I send data out of a serial port on my main thread. I wait for a...
1
by: Kevin | last post by:
In a newsgroup thread from Jan 8, 2003 between Barry Holsinger and the VBDotNet Team, please review this excerpt: "You understood my problem completely. Your sample code provides a really...
9
by: koschwitz | last post by:
Hi, I hope you guys can help me make this simple application work. I'm trying to create a form displaying 3 circles, which independently change colors 3 times after a random time period has...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.