473,765 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to start new process from inside BackgroundWorke r?

rauty
16 New Member
Hi all,

I have a situation where I'm using BackgroundWorke r to run a long process in the background. However, whenever it runs I keep getting the following error:

"TargetInvocati onException was unhandled"


The culprit seems to be this guy:
Expand|Select|Wrap|Line Numbers
  1. Dim GrainProcess As New Process()
In my DoWork sub I'm calling a sub in another module. The above line is in the middle of that other sub. I'm using Process.Start to run a Matlab executable file (not written by me) that processes an image and spits out a number.

I tried putting the Dim statement outside the sub, but then it just gives me the same error a couple of lines down when I try to set the .StartInfo properties.

Does the "was unhandled" part of the above exception mean that I need to provide some kind of error checking (maybe a try...catch), or does it mean that I'm not allowed to do a Process.Start from within a BackgroundWorke r thread?

I'm pretty new to threading in general, so any help would be greatly appreciated. Code examples would be very helpful, since I'm not a programmer by nature and can't always make heads or tails out of what I read in the Microsoft Documentation.

Please also let me know if you need any additional info.

Thanks for your time!
Apr 2 '09 #1
1 3204
rauty
16 New Member
Well, I tried putting the Process.Start routine in a Try...Catch block, but that didn't make any difference. One thing is, when the error occurs, the line
Expand|Select|Wrap|Line Numbers
  1. OutputString = Trim(.StandardOutput.ReadToEnd)
is highlighted in light gray, along with the Catch section. Here is all of the code I use to run the executable (from within the BackgroundWorke r):
Expand|Select|Wrap|Line Numbers
  1. Try
  2.             ' Call MATLAB routine (grain.exe) to calculate grain
  3.             Dim GrainProcess As New Process()
  4.             Dim OutputString As String
  5.             Dim GrainInfo() As String
  6.  
  7.             ReDim Preserve GrainArray(GrainCount)
  8.             ReDim Preserve MatlabLstar(GrainCount)
  9.             ChDir(MatlabDir)
  10.             With GrainProcess
  11.               With .StartInfo
  12.                 .UseShellExecute = False
  13.                 .RedirectStandardOutput = True
  14.                 .RedirectStandardError = True
  15.                 .CreateNoWindow = True
  16.                 .FileName = "grain.exe"
  17.                 .Arguments() = ImgSaveMode & " RawImg.bmp " & ICCfile
  18.               End With
  19.               .Start()
  20.               OutputString = Trim(.StandardOutput.ReadToEnd)
  21.               ' Clean up the output (get rid of spaces, LF, etc.)
  22.               GrainInfo = Split(OutputString, vbLf)
  23.               Array.Copy(GrainInfo, 2, GrainInfo, 1, 1)
  24.               ReDim Preserve GrainInfo(1)
  25.               GrainInfo(1) = Trim(GrainInfo(1))
  26.               GrainArray(GrainCount) = GrainInfo(0)
  27.               MatlabLstar(GrainCount) = GrainInfo(1)
  28.               .WaitForExit()
  29.             End With
  30.           Catch ex As Exception
  31.             MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Error Accessing grain.exe")
  32.             ex = Nothing
  33.           End Try
See below for a screen capture with highlighted areas:


For some reason I can make calls to functions within a DLL from the BackgroundWorke r, but can't start a new process. Any help with this would be greatly appreciated!
Apr 3 '09 #2

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

Similar topics

3
1893
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this case it does gets all files from a directory. then i need to update the GUI with information from the thread... the thread should be started with a parameter, in this case its a string
5
14134
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...
6
1789
by: Kyote | last post by:
I'm trying to make, what I thought, would be a simple application. This application will help me organize files I have a lot of, on my computer(ebooks, pictures, etc..). I'm currently dealing with over 25,000 files in a couple hundred directories. I'm currently trying to collect the list using this Try For Each foundfile As String In My.Computer.FileSystem.GetFiles(mySource,
4
2337
by: Diego F. | last post by:
Hello. I have a process that can take a long time and I'm trying to put an animated gif while the user is waiting. I added a panel with a picturebox with the image inside. The panel is not visible when the application starts, but before the process, I make it visible. The problem is that while the long process is running, the image doesn't appear. The panel is empty.
5
2383
by: Manikandan | last post by:
Hi, My application is processing a database(selecting data using execute reader) It takes much time. I want to show user the application is running, showing some information in the form I tried with thread, timer, but not helpful any simple idea to show user application is not frozen Thanks,
4
2460
by: Marcolino | last post by:
Hi All, I'm using this code provided by Michael to run Async process: http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/3dda80ed45e6176e/606d19fccc330588#606d19fccc330588 Now I have a new need. I have to start a Soubroutine when the Async process is finished. Many Thanks.
32
1706
by: John Wright | last post by:
I have a long process I run that needs to be complete before the user can continue. I can change the cursor to an hourglass, but I want to update the Status Strip on the bottom during the process. I set the statusstrip label to "Downloading...", but it will not show up on the form. I need to display this message before it starts the process. I can put a thread.sleep for 1 second after I do the initial process, but that seems sloppy to me. ...
4
6401
by: =?Utf-8?B?U3ZlbiBXLg==?= | last post by:
Hi Newsgroup, I am developing a C# Windows Forms application that launches processes within a background worker.. The processes seem to have a memory limit of about 278mb. Some proccesses that get to that amount of used memory seem to hang ;-( Is there a memory limit that can be adjusted ?? The physical machine has 3
4
4803
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, I have winForm that needs update Panel (add controls to Panel of SplitContainer dynamically). I have a Backgroundworker, and DoWork event I want to add controls but I get this error in Spanish (I don't get translation: Los controles creados en un subproceso no pueden tener controles primarios en un control en un subproceso diferente.)
0
9399
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,...
1
9955
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
9833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7378
isladogs
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...
0
6649
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
5275
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
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.