473,805 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Backgroundworke r questions

Is the following OK in Backgroundworke r:

Private Sub backgroundWorke r1_DoWork(ByVal sender As Object, ByVal e As
DoWorkEventArgs ) Handles backgroundWorke r1.DoWork

Static index As Integer = 700

Dim filename As String

filename = "Image_" & index.ToString( "D4")

'NOTE THE CONTROL WebBrowser1 IS USED

Dim bmp As Drawing.Bitmap = SomeMethod(WebB rowser1.Handle)
bmp.Save("C:\Si teShow\" & filename & ".bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

index += 1

End Sub

or do I need to call something like this.

Private Sub SetText(ByVal [text] As String)
If Me.textBox1.Inv okeRequired Then
Dim d As New SetTextCallback (AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.textBox1.Tex t = [text]
End If
End Sub
although it's not clear to me how to adapt the above!

if I want to do it repeatedly can I in a Timer click event do:
Private Sub Timer1_Tick(... ) Handles Timer1.Tick

If Me.backgroundWo rker1.IsBusy Then

Exit Sub

Else

Me.backgroundWo rker1.RunWorker Async()

End If

End Sub

Thanks for any help at all


Aug 1 '08 #1
1 967
I personally prefer the "Is invoke required?" approach. I primarily use it
in (database) projects where tasks have to be threaded and the UI usable all
the time and updated regularly.

Best Regards,
Stanimir Stoyanov | www.stoyanoff.info

"AAaron123" <aa*******@road runner.comwrote in message
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
Is the following OK in Backgroundworke r:

Private Sub backgroundWorke r1_DoWork(ByVal sender As Object, ByVal e As
DoWorkEventArgs ) Handles backgroundWorke r1.DoWork

Static index As Integer = 700

Dim filename As String

filename = "Image_" & index.ToString( "D4")

'NOTE THE CONTROL WebBrowser1 IS USED

Dim bmp As Drawing.Bitmap = SomeMethod(WebB rowser1.Handle)
bmp.Save("C:\Si teShow\" & filename & ".bmp",
System.Drawing. Imaging.ImageFo rmat.Bmp)

index += 1

End Sub

or do I need to call something like this.

Private Sub SetText(ByVal [text] As String)
If Me.textBox1.Inv okeRequired Then
Dim d As New SetTextCallback (AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.textBox1.Tex t = [text]
End If
End Sub
although it's not clear to me how to adapt the above!

if I want to do it repeatedly can I in a Timer click event do:
Private Sub Timer1_Tick(... ) Handles Timer1.Tick

If Me.backgroundWo rker1.IsBusy Then

Exit Sub

Else

Me.backgroundWo rker1.RunWorker Async()

End If

End Sub

Thanks for any help at all

Aug 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2702
by: elziko | last post by:
I know I can stop my thread by using the CancelAsync method of the BackgroundWorker but that requires me to monitor the value of the CancellationPending property in my BackgroundWorker.DoWork event. This means that if the DoWork event is processing a single line of code then my code must wait for this line to finish before it can check the value of CancellationPending. What if the user wants to cancel before I can check this value? Is...
5
14135
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
1
3236
by: Bob | last post by:
Hi, I am having trouble seeing how this bolts together. The UI starts a process which involves a long running database update. All Database activity is handled by a class called DT. DT has a progress event. So I added a bw to the form. The Dowork Calls a method which instantiates a DT and calls its Dataprocessing method.
14
6396
by: =?Utf-8?B?SXNobWFlbA==?= | last post by:
Hi, I have a form with a progress bar on it and wanted to use the BackgroundWorker to be able to update the progress. I looked at examples, run some of them, but in debug, when the code gets to the do work method, it stops for a long while and then executes the first line of the method and the doesn't do anything else. What am i doing wrong?
0
2483
by: Chris | last post by:
I would like to be able to pass the BackgroundWorker object and DoWork Event Args to a second function (third function?) and be able to still report the progress. I'm getting the following exception when trying to access BackgroundWorker.CancellationPending or e.Cancel An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll Additional information: Exception has been thrown by the target of...
2
4840
by: Chris | last post by:
When I try to access the backgroundWorker.CancellationPending property I get the following exception: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll Additional information: Exception has been thrown by the target of an invocation. I am using the backgroundWorker in a component that I am trying to make for doing encryption of large files in the background.
9
18036
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form will almost always lead to the user opening a certain child window that's fairly resource intensive to load. Is it possible to load this form in a backgroundworker and then use the Show method and hide method as necessary? Anyone know of
4
2585
by: Sin Jeong-hun | last post by:
This is what I've always been wondered. Suppose I've created a class named Agent, and the Agent does some lengthy job. Of course I don't want to block the main window, so the Agent does the job in a separate thread. If the job is progressed it fires an event, and the main window handled the event by changing the value of a progress bar. The problem is that this event is fired in another thread so when the handler in the main window tries...
2
1938
by: Marcel Overweel | last post by:
Hello, I am using a BackgroundWorker as a base class for several workers in a windows service application. Because BackgroundWorker is derived from Component, Visual Studio (2008) shows the message "To add components to your class, drag them from the ToolBox....." Is there a way to tell Visual Studio not to show this message and just show the sourcecode whenever I doubleclick on the cs file of the class?
2
11873
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have introduced a component to my solution that is throwing an exception about needing to be run in single threaded apartment mode. This component is created in an async call by a BackgroundWorker object, which seems to be on a MTA thread. Is there a way for me to get the BackgroundWorker thread to run in STA mode, or do I have to remove the BackgroundWorker and hand spin my own async call?
0
9716
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, 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...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10366
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,...
0
6876
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();...
0
5542
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...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
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...

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.