Notifies The Main Thread Via A Delegate Sub?

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


ADVERTISEMENT

Call A Method That Started On A Background Thread On The UI Thread Calling BeginInvoke And Passing In A Delegate?

Aug 27, 2011

I am trying to call a method that started on a background thread on the UI thread calling BeginInvoke and passing in a delegate as follows:

Dispatcher.BeginInvoke(Function() UpdateApplicationDataUI())

to call this method:

Private Sub UpdateApplicationDataUI()
...
End Sub

However, I get an error in the call to BeginInvoke (the UpdateApplicationDataUI portion of the delegate is stating "Expression does not produce a value").

Me.Dispatcher.BeginInvoke(Function() New Action(AddressOf UpdateApplicationDataUI))

View 1 Replies

Write In Worker Thread In A Data Table And Rich Text Box in Main Thread

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

Creating A Progress Bar That Runs On Another Thread While Keeping Calculation In Main Thread

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

Thread State - Thread In An Application Which Calls A Sub Routine Main()

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

Access Objects Of Main Thread From BackgroundWorker's Thread?

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

Fire An Event In Main Thread From Another Thread?

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

Run A Method On The Main Thread From A Separate Thread?

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

Use A Delegate To Update Text Of Main Form From DoWork Event Of BackgoundWorker?

Mar 26, 2010

How would you create and use a delegate to update the text of the main form from the DoWork event of a backgoundWorker?

View 4 Replies

Call A Delegate From Separate Thread?

Jun 10, 2011

So, I'm having troubles implementing a separate thread. This is because I have a simple class, and in it I start a new thread. So, as it is not any form, I haven't found any way to make it call the function in the UI Thread.

So, I cannot use the Invoke method. Is there any way to call a function from another thread?

View 2 Replies

Executing Delegate In Existing Thread?

Aug 5, 2009

I have a GUI which executes on the GUI-thread. Further I have another thrad which does video processing using DirectShow (this is COM).

- Now I want to execute a function on the same thread as where the videoprocessing is executing. This is initiated by the GUI-thread. Touching the COM-referenced object goes wrong if a execute the function from another thread (I understand that). When a call the function from the same thread everything goes fine. But to do this I have the poll some flag-bits in the mainloop, and that is not a 'pretty' solution...

All discussions on the internet are about how change the GUI from a different thread.

I have tried several things:

1) Invoke the function using a delegate. This doesn't wordt, since the function is executed in the GUI thread. (checked bu ThreadID's)

2) BeginInvoke the function using a delegate. May be .net executes the function in a original thread where the object has been created. This does also not work: .net used random threads (probaby from the threadpool)

3) ISynchronizeInvoke, Threading.SynchronizationContext and some other features seems only to work on the GUI thread only...

The question: Is there a way to Post, Send of Invoke a delegate on the specific thread (for example by a reference to this thread or threadID)

View 12 Replies

Thread Do Not Resume When The Delegate Returns?

Jun 2, 2010

It seems that there is a glitch in Vb, While having some tasks ( Thread ) queued using Tasks if you try to use Invoke, the thread do not resume when the delegate returns.If BeginInvoke is used, it works but the problem is that it become impossible to execute a delegate synchronously.This does force the use of the AutoResetEvent to control the thread.The problem comes when the thread execute some code in a other classes, using a single AutoResetEvent within many classes just give a very dirty code.

View 1 Replies

C# - Abort A Thread Started With Delegate.BeginInvoke?

Feb 1, 2010

Disclaimer: I know that Thread.Abort is evil. I'm using it as a last resort since some I/O functions (e.g., File.Exists when used on a non-existing network share) block for a large amout of time and do not allow you to specify a timeout.

Question: Is it possible to Abort (as in Thread.Abort) a worker thread started using Delegate.BeginInvoke or do I have to do the Thread handling myself?

View 2 Replies

Invoke Parameterized Function Delegate From Background To UI Thread?

Oct 4, 2010

What is the Invoke syntax to marshall data from a background thread receive callback method to a function on the UI Thread?(Form1).

Public Class Form1
MyDelegate = New DisplayData(AddressOf DisplayData)
Private Sub Form1_Load()
MyDelegate = New DisplayData(AddressOf DisplayData)

[code]....

View 12 Replies

Run Task On Main Thread?

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

Marshal Back To Main Thread?

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

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

Using A Timer To Delay Main Thread?

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

[2008] Running In Main Thread?

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

Separate Thread Accessing To Main Ui Controls?

Aug 25, 2009

how to access the main ui's labels from a delegate method?

View 7 Replies

Multicast Delegate: Represents A Multicast Delegate; That Is, A Delegate That Can Have More Than One Element In Its Invocation List?

Jan 30, 2010

from the documentation we have this: Multicast Delegate: Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.

so am i right to say that Multicast delegate is no different from a normal delegate other than the fact that it has arguments. so System.Action is a 'normal' delegate whereas System.Action(T)(Byval obj as T) is a multicast delegate?

View 5 Replies

Multithreading - How To Ensure That A Code Is Running On Main Thread

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

Put Method In Main Thread From Background Without Declaring Delegates?

Nov 23, 2009

put method in main thread from background without declaring delegates

View 2 Replies

VS 2008 TCP Client Responding To The Main Thread Like Winsock?

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

VS 2010 - Process Exe Thread Is Halting Main Application?

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

VS 2010 Thread To Check Main Program Execution

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

Access Progress Bar On Main Form From Thread On User Control?

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

C# - Background Worker In External Reference (DLL) Locking Main Thread?

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

Call A Function In Module And Get Result In The Main Thread Asynchronously

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

Forms :: Access Main Form From Second Thread Running In A Module?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved