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: - 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!
1 3206
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 - 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): - Try
-
' Call MATLAB routine (grain.exe) to calculate grain
-
Dim GrainProcess As New Process()
-
Dim OutputString As String
-
Dim GrainInfo() As String
-
-
ReDim Preserve GrainArray(GrainCount)
-
ReDim Preserve MatlabLstar(GrainCount)
-
ChDir(MatlabDir)
-
With GrainProcess
-
With .StartInfo
-
.UseShellExecute = False
-
.RedirectStandardOutput = True
-
.RedirectStandardError = True
-
.CreateNoWindow = True
-
.FileName = "grain.exe"
-
.Arguments() = ImgSaveMode & " RawImg.bmp " & ICCfile
-
End With
-
.Start()
-
OutputString = Trim(.StandardOutput.ReadToEnd)
-
' Clean up the output (get rid of spaces, LF, etc.)
-
GrainInfo = Split(OutputString, vbLf)
-
Array.Copy(GrainInfo, 2, GrainInfo, 1, 1)
-
ReDim Preserve GrainInfo(1)
-
GrainInfo(1) = Trim(GrainInfo(1))
-
GrainArray(GrainCount) = GrainInfo(0)
-
MatlabLstar(GrainCount) = GrainInfo(1)
-
.WaitForExit()
-
End With
-
Catch ex As Exception
-
MsgBox(ex.Message, MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Error Accessing grain.exe")
-
ex = Nothing
-
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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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,
|
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.
|
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,
| |
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.
|
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. ...
|
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
|
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.)
|
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,...
|
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: 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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
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...
| |