Pass A String To The Main Thread?
Jul 14, 2011
I have written a program that performs multiple httpwebrequests. It reports in to me by writing to the console. In the past, i have used a backgroundworker for this task, but the code became ugly and bulky. Now, i use threading.thread to start the background process. However, i can't seem to find an explanation on updating the UI from the worker thread.
I've read a lot on delegates, invoke and lambda's, and i just got more confused.
Let's say, in my current program i have this line to be displayed in a textbox on my main form:
"Error reading events!"
View 2 Replies
ADVERTISEMENT
Mar 4, 2009
I'm creating a Client Server application which involves theServer running some scripts in clients and getting back results in an automated way. In Server, other than Main thread, i have 2 worker threads, a) one monitoring response from clients and b) the other scheduling next available job to respective client which executes that job. The issue here is ,I want these worker threads to write the status of their work in the UI(which comes under Main Thread). Also i need to write things in worker thread in a Data table and Rich Text Box in Main thread. But, I can't do so, since it has been blocked to access one thread's function or property directly from others. Is there any work around to do this?
View 8 Replies
Nov 12, 2009
Preface: I know this is an unusual/improper way to do this. I can do this with a "real" ShowDialog(), background worker/thread, and so on. I am trying to do specifically what I describe here, even if it is ugly. If this is impossible for X reason, I have created a fancy progress dialog for some of our long running operations. I need to have this dialog shown on a new thread while having processing continue on the calling (UI in most cases) thread.
[Code]...
View 3 Replies
Jul 26, 2010
I have a thread in an application which calls a sub routine Main(). The Main sub routine in turn call several sub routines/functions from with the same module,several different classes in the same application. Also some sub routines/functions call routines from a class library. Now say the routine/function in class library goes into a infinite loop and never returns. I would like my thread in the application to raise a event and display message to the users about the infinite loop. I am giving some sample code for the application.
Imports System.Threading
Module VMain
Public gbSuspend As Boolean
[CODE]...
View 7 Replies
Aug 4, 2011
I'm working with BackgroundWorker, I want the BackgroundWorker do the retrieval process of data from database while the user can still do another task on the form. The problem is, after retrieving the data, I can't seem to access the ListView in my Form from the DoWork event of BackgroundWorker, I will populate that ListView using the data I've retrieved.
Consider this example, this is how I'm doing it:
Public Class Test
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
[Code].....
View 1 Replies
Sep 24, 2009
could someone tell me how to fire an event in main thread from another thread as well as fire and forget without use a new thread?
View 9 Replies
Dec 31, 2010
I'm reading data from a serial port, but the DataReceived event of SerialPort is handled on it's own thread. I want to handle this on the main thread, but simply declaring an event and raising it still results in it being processed on the SerialPort thread. I'm assuming I need to declare a delegate I can call, but I don't see how that would work.
For example, I want to call Sub HandleDataReceived() on the main thread from the DataReceived thread, having HandleDataReceived() run on the main thread. How would I do this?
View 1 Replies
Mar 23, 2011
I have an application that displays real time data. Queries are made to a MySQL database on another PC over the internet every 10 seconds to gather the most recent data.Originally I did the query within a BackgroundWorker so that the GUI is still responsive while the query is answered. However, I found that I need a timeout on the database query (as sometimes it hangs without generating an error) and couldn't do this within the background worker.
So now I'm trying to do it with threads. I have managed to run a thread to get the data.I need to understand how to run a task on the main thread when the GetDataThread is complete. If I do this using Events as shown below then Sub GetDataComplete is running as part of the GetDataThread not the Main Thread. I want to run a sub like backgroundWorker1_RunWorkerCompleted (this seems to run on the main thread).
My Main thread is called MainThread
VB
Imports System.Threading
Imports System.ComponentModel
[code]....
How can I run a task on the main thread when the GetDataThread is complete.
View 9 Replies
Dec 15, 2009
I am using a COM library in my VB.NET app that has an asynchronous execution method and signals my application via an event when it completes. The event handler is on a different thread from the calling thread. I want to invoke another execution on the main thread when I receive the completion event. If I call directly in the event handler for another execution it starts on the new thread. How do I marshal back to the main thread. This is done in a dll not in a form.
View 3 Replies
Mar 3, 2012
i have a background thread when it is done doing its task it notifies the main thread via a delegate sub it seems if the main thread is "busy" then the background thread hangs waiting for the main thread. if this is normal, which i assume it is my background thread, starts another thread, and this 2nd background thread makes the delegate call is this bad practice?
View 2 Replies
Feb 3, 2011
is the first time I tried to use a timer - can't understand why it doesn't work!I need to suspend the main thread for a preset time 'delaymSecs' then let the thread continue.I tried this code fragment:-
System.Timers
'(etc)
Public
[code].....
View 1 Replies
Mar 2, 2009
Well basically I have something being done in a new thread and I would like to start a sub not in the same thread, but in the main thread. How do I do that?
View 3 Replies
Aug 25, 2009
how to access the main ui's labels from a delegate method?
View 7 Replies
Oct 23, 2010
I've constructed a custom System.Windows.Forms.Form that requires arguments to New. I want to use one of these as the MainForm in a Windows Forms Application. How do I get the Application Framework to pass those arguments as needed?
View 1 Replies
Jan 21, 2012
It's easy to do so in objective c but I do not know how to do so in vb.net update:I know about control.invoke. But control.invoke requires a control that may change from program to program. What would be the easier way?So yes program is winform. However I need a solution that does not depend on any specific control. If that's the case actually I do not need things to be run on main thread do I?
View 2 Replies
Nov 23, 2009
put method in main thread from background without declaring delegates
View 2 Replies
Apr 15, 2010
I have a user app written in VB which up till now has relied on winsock to connect to another device we have. The user app logs onto the device and then send / receives status reports from it which are used to set the controls on the apps forms.
This has all worked well for a long time but I'm now looking to move away from Winsock as I know it's not 'the right way' to do things and I also need to be able to send non ascii characters between the app and the device it's connected to (implementing multi language support).
The issue is with Winsock it would simply throw the DataArrival event when a message was received and I could then process the message and act upon it. When using a TcpClient socket connection I'm running into problems as all responses are on the socket thread which means I can't simply change controls on the main form without using the Invoke check.
What I want to be able to do is have the thread running the TcpClient simply alert the main form thread when it receives data and make that data available to the main thread so it can start processing it and triggering all the other functions etc required (these also interact with the Form). Whilst this is happening the TcpClient monitors any further messages and sends response messages as requested from the main thread.
View 9 Replies
Feb 10, 2012
I have two applications. For performing certain functions, i run a second exe, via a process, and wait till it is complete (exited) to continue with my main application. I run through many repetitive functions on different files.Everything runs fine however, when i am doing a run and it is on the x loop number, the main application seems to halt the secondary process exe. I can only assume this is what is happening as, if i close/stop (not pause) my main application in VB, the second exe continues from where it was halted until it completes.
View 4 Replies
Apr 27, 2011
I feel like the answers I seek are rather obvious so I feel silly for having to ask, but I just can't seem to figure this out (I'm new to threads, and am really only comfortable using them in Java at the moment). I have an Excel Addin application created with VB.NET, and I've noticed that occasionally while it's running some code (it's no one specific block of code) the program execution will just stop. This is especially problematic when I've set ScreenUpdating to False for Excel because the users then have to completely close out of Excel to get ScreenUpdating to true.
[Code]...
View 8 Replies
Aug 18, 2009
I have a windows application with a main form, on which a user control is added dynamically when a device connects trough USB.
On a user control, there is a thread wich is getting data from the device trough USB and when it is finished, I want to change a progressbar that is located on the main windows form where user control reside.
This is the code that is I call on the user control thread to change the progress bar value:
Frm_Main.UpdateProgressBar(CInt((AllBytesReceived / MaxBytesInFlash) * 100))
and this is a code that is called on the main form:
Private Delegate Sub UpdateProgressBarDelegate(ByVal value As Integer)
[Code]....
View 8 Replies
Mar 21, 2011
I use background worker almost daily and works great. Today I came to an instance though where I needed to put my background worker in a separate project then the one I was running because I needed to use this class in two different projects in my solution. When I tested the coding on a winforms form, it works perfectly, handling my coding on the background thread. When I try to reference this class from an external project, all of my coding seems to run just fine, but it does not appear to be doing anything on a background thread as it should be, causing my main window to lockup.
Is there any way around this / what is the best practice for ASYNC calls in an external class.Note I basically created a class that u call start, and an event fires when data is ready, so it's not like my external project is waiting for the method to complete.
Solution ABC has two projects. Project A and Project B. Project A is my WPF application and B is my DLL doing the work. Inside project A I have
Dim SmartCardData as new Solution.B()
SmartCardData.Start()
Project B has a sub
[code]....
View 3 Replies
Mar 2, 2011
I have a function in a module that returns a datatable.I need to call that function asynchronously and get the results in the Main thread (Main Form) in vb.net.
View 2 Replies
Jun 22, 2010
I was a vb6 user, done a few projects only with forums Now i am moving to vb.net(vb2010) and i have some trouble.Lets say we have a form(form1), a module(mod1) and a textbox on the form1.
i want to start a Sub (DoWork) in the module but in a new thread.
Dim Thread1 As System.Threading.Thread
Thread1 = New Threading.Thread(AddressOf mod1.DoWork)
Thread1.Start()
The DoWork sub does some stuff and when it's finished i want to change the text of a textbox1 in the main form and start another sub (DoWork2) on the main form under the main thread not the one DoWork is running under.
Plese do not refer me to another post that mighe give me a part answer, try to explain to me what i have to do and why.
View 3 Replies
Dec 4, 2009
I have a console application (VB.NET). When it is started, it spawns worker threads to find work in the database and do the task, then look for the next task (A workflow basically).
The problem that I have is that I have my Event Handler in the main thread that spawns the worker threads. Those workers, if they error, raise an event to a public delegate. However my main thread is not detecting these events, and I cannot figure out how to make it. My intention is to do all logging (text/database), email alerts, and restarting the worker to find another task that is not errored. (This will be expanded in the LogErrorMessage routine and such, for now I am just keeping it a simple Console.Writeline so that I can see if the method is being fired or not)
Here is the code around what I am trying to do:
Logger Class:
Public Delegate Sub LogDelegateError(ByVal Ex As Exception)
Public Class EventLogger
Public Event EventError As LogDelegateError
[Code].....
View 2 Replies
Sep 4, 2009
I have a standard windows application called winap. I have a com component which acts as an api to the winap. I have a class in winap call classapi which has all the methods that the api calls and all works well. The problem is that one of the methods in my class api needs to get a handle on form elements in the main worker thread. Whenever I try to access an existing form I keep getting null because the for exists in the main worker thread and my api call is in a seperate thread.
[Code]...
View 5 Replies
Dec 31, 2010
Is it possible to wait/suspend execution for a certain amout of time without hanging the main UI thread?
View 7 Replies
Dec 21, 2010
I have a program which has a rather complicated component within it. This component has a number of features that all run at once and will cause lag with the main application which isn't acceptable.
To resolve this issue I'd like to run these processes on the component in another thread. I've created a simple test version to work out how I'm going to do this, however I've run into a few problems.[code]...
View 1 Replies
Jun 2, 2010
[code]...
Is there any issues with this? If I'm kicking off half a dozen threads over and over? ie: I'm not using a system where the parameters will get mixed up/corrupted?
I've looked around, and if this is OK/safe to use, this seems the easiest way to get values/params into a thread.
View 5 Replies
Feb 21, 2010
Im trying to call a procedure to run into a thread..But this procedure requires two arguments. How can I pass these arguments in to the function when the thread call:
Dim myThread As New Threading.Thread(New Threading.ThreadStart(AddressOf PopulateTermList myThread.Start()
addressof PopulateTermList should only be called without parenthesis(the VB tells me this)
View 5 Replies
Oct 25, 2010
I'm looking to pass two or more parameters to a thread in VB 2008.
The following method (modified) works fine without parameters, and my status bar gets updated very cool-y. But I can't seem to make it work with one, two or more parameters.
This is the pseudo code of what I'm thinking should happen when the button is pressed:
Private Sub Btn_Click()
Dim evaluator As New Thread(AddressOf Me.testthread(goodList, 1))
evaluator.Start()
[Code].....
View 5 Replies