I found this awesome example of calling a Main Thread from a worker
thread on abstractvb.com but I read through the example and would like
to see if anyone can clarify some of this code below:
Questions:
1. The Public Sub New proceedure. Is that just a proceedure named
new or is there more to this? I went through the code and I do not
see any refrences to 'New'
2.Does anyone have any really good links to threading articles. The
microsoft links that I have are not clearly illustrated.
Imports System.Threadin g
Public Delegate Sub CallBack(ByVal intTotal As Integer, ByVal
strThreadName As String)
Public Class Counter
Private LabelToUpdate As Label
Private MaxCount As Integer
Private CallBackMethod As CallBack
Public Sub New(ByVal l As Label, ByVal intMax As Integer, ByVal cb
As CallBack)
LabelToUpdate = l
MaxCount = intMax
CallBackMethod = cb
End Sub
Public Sub BeginProcessing ()
Dim i As Integer
For i = 1 To MaxCount
LabelToUpdate.T ext = i
LabelToUpdate.R efresh()
Next
CallBackMethod( i - 1, Thread.CurrentT hread.Name)
End Sub
End Class
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim c1 As New Counter(Label1, 3000, AddressOf ThreadCompleted )
Dim c2 As New Counter(Label2, 1000, AddressOf ThreadCompleted )
Dim t1 As New Thread(AddressO f c1.BeginProcess ing)
Dim t2 As New Thread(AddressO f c2.BeginProcess ing)
t1.Name = "Counter Thread 1"
t2.Name = "Counter Thread 2"
t1.Start()
t2.Start()
End Sub
Private Sub ThreadCompleted (ByVal intValue As Integer, ByVal strName
As String)
MsgBox("Thread " & strName & " has completed at " & intValue)
End Sub 1 1617
Found my answers:
Public New is the class requirements.
And Callback returns the values.
Scary. I'm starting to understand this subject.
"Peter" <pe***@mclinn.c om> wrote in message
news:dc******** *************** **@posting.goog le.com... I found this awesome example of calling a Main Thread from a worker thread on abstractvb.com but I read through the example and would like to see if anyone can clarify some of this code below:
Questions:
1. The Public Sub New proceedure. Is that just a proceedure named new or is there more to this? I went through the code and I do not see any refrences to 'New'
2.Does anyone have any really good links to threading articles. The microsoft links that I have are not clearly illustrated.
Imports System.Threadin g
Public Delegate Sub CallBack(ByVal intTotal As Integer, ByVal strThreadName As String)
Public Class Counter Private LabelToUpdate As Label Private MaxCount As Integer Private CallBackMethod As CallBack
Public Sub New(ByVal l As Label, ByVal intMax As Integer, ByVal cb As CallBack) LabelToUpdate = l MaxCount = intMax CallBackMethod = cb End Sub
Public Sub BeginProcessing () Dim i As Integer
For i = 1 To MaxCount LabelToUpdate.T ext = i LabelToUpdate.R efresh() Next
CallBackMethod( i - 1, Thread.CurrentT hread.Name) End Sub End Class
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click Dim c1 As New Counter(Label1, 3000, AddressOf ThreadCompleted ) Dim c2 As New Counter(Label2, 1000, AddressOf ThreadCompleted )
Dim t1 As New Thread(AddressO f c1.BeginProcess ing) Dim t2 As New Thread(AddressO f c2.BeginProcess ing)
t1.Name = "Counter Thread 1" t2.Name = "Counter Thread 2"
t1.Start() t2.Start() End Sub
Private Sub ThreadCompleted (ByVal intValue As Integer, ByVal strName As String) MsgBox("Thread " & strName & " has completed at " & intValue) End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matthew Bell |
last post by:
Hi,
I've got a question about whether there are any issues with directly
calling attributes and/or methods of a threaded class instance. I
wonder if someone could give me some advice on this.
Generally, the documentation suggests that queues or similar constructs
should be used for thread inter-process comms. I've had a lot of
success in doing that (generally by passing in the queue during the
__init__ of the thread) and I can see...
|
by: Ted Miller |
last post by:
Hi folks, I originally posted this on
microsoft.public.dotnet.framework.interop. Reposting to broaden the
audience.
I'm having an interop problem where my managed component is reentered from
COM on the wrong thread, at which point things seem to go downhill very
rapidly. I'm successfully making very heavy use of COM interop elsewhere in
my C# code, but I'm having trouble finding a way around this particular
problem. This is VS .Net 2003.
|
by: Bryan |
last post by:
I have a multi-threaded C# console application that uses WMI
(System.Management namespace) to make RPC calls to several servers (600+ )
and returns ScheduledJobs. The section of my code that performs the query
is contained in a delegate function that I execute via a second thread. On 1
or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join()
coupled with a Thread.Abort() but this does not kill the thread.
Based on...
|
by: Hao L |
last post by:
For example,
void WorkerMethod() { ... UnregisterAllHotkeys();}
void UnregisterAllHotKeys { for(...) {UnregisterHotKey(...);}}
UnregisterHotKey is an API function that must be on the thread that
RegisterHotKey was called in order to unregister any of the hot keys
RegisterHotkey registered. ("The UnregisterHotKey function frees a hot
key previously registered by the calling thread.") Is there any way to
call UnregisterAllHotkeys, a...
|
by: Chad Miller |
last post by:
I know haw to call a the main thread from a worker thread in a windows form
class, but
how does a worker thread call its main thread from a none windows form
class?
Thank You.
chadm@predictiveconcepts.com
| |
by: Tim |
last post by:
The are 2 threads - main thread and worker thread. The main thread
creates the worker thread and then the worker thread runs in an infinite
while loop till it is asked to exit by setting an event. The worker thread
instantiates an object and calls methods of that object. If some method call
fails, the main thread needs to be notified about the failure. What
mechanisms exist for notifying the main thread about the worker thread's
status -...
|
by: Joe Jax |
last post by:
I have an object that spawns a worker thread to process one of its methods.
That method processes methods on a collection of other objects. During this
processing, a user may request to cancel the entire operation. I could
request abort on the worker thread, but that is a) potentially messy, and b)
not guaranteed to take immediate effect anyway. I would rather have some way
of allowing the main thread to tell the worker thread that it...
|
by: bytebugs |
last post by:
Hi,
As a matter of principle I have refranied from creating an instance of
Form or UserControl from within a class that does not inherit from
System.Windows.Form.
I am looking for comments on Pros and Cons of the approach.
My logic has been that UI is always executed on the main application
thread. I use Control.InvokeRequired or delegates to ensure that I am
|
by: Klaus |
last post by:
Hi,
I have an existing VC 6 MFC application which communicates asynchronly with
a VC 2005 managed code dll.
I use an unmanaged base class with virtual functions to access methods in
the MFC application.
Furthermore, I use a pointer to an unmanaged function to jump back into the
managed dll.
The managed part is basically a remoting enhancement which asynchronly
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |