0

I'm working on an old VB legacy application, and I'm sort of struggling to get my bearing of things.

Basically from what I understand this application essentially takes a file, and throws it into an executable, that's pretty much it. The client wants this to be done with multiple threads, however the person that worked on this application before me does not work here anymore.

At some point in an asynchronous there's the offending line of code:

Dim exeProcess As Process
Dim exeInfo As New ProcessStartInfo

' presume that appFile is in the same path as the executable
With exeInfo
   .FileName = _AppPath & "\" & _Executable
   .Arguments = arg
   .UseShellExecute = False
   .WorkingDirectory = _WorkingFolder
End With

Dim mutex As Mutex = New Mutex(False, "namedMutex")

mutex.WaitOne()
exeProcess = Process.Start(exeInfo)
_RunningProcess = exeProcess
exeProcess.WaitForExit()
exeProcess.Close()
mutex.ReleaseMutex()

If I comment out the mutex.WaitOne() and mutex.ReleaseMutex() the process it starts throws errors about not being able to create new files. The previous person that worked on this left a comment about how there's synchronization issues, which is why the mutex is necessary.

I don't really have much knowledge of visual basic, and as it stands I'm basically clueless as to what I'm supposed to do. If anybody has any suggestions on what I can do to even approach solving this problem I will be very grateful. I apologize for not providing more information in this post, this is basically what I'm working with. /:

braX
  • 11,506
  • 5
  • 20
  • 33
aitbg
  • 27
  • 3
  • Don't comment out the mutex. You'll need to contact the owner of the program you start to get the support you need. – Hans Passant Nov 11 '19 at 21:16
  • 1
    The person asking for multiple threads doesn't know what they're talking about. You can't throw additional threads at I/O work, that's not what threads are for. Threads are for CPU work, not I/O. – Mathieu Guindon Nov 11 '19 at 21:21
  • Does the code run on a desktop or a server with a RAID array or otherwise managed storage? How many CPU cores are there? See https://stackoverflow.com/q/902425/1188513 and consider letting the framework deal with threads, and have your code deal with `Task` instead. – Mathieu Guindon Nov 11 '19 at 21:26
  • @MathieuGuindon It runs on a desktop, and I believe the user is able to manually set how many cores they have. I think you're right though, this work just doesn't seem right to me, thanks for the help! – aitbg Nov 11 '19 at 21:53
  • The desktop presumably has one single hard drive. Consider how many concurrent reads/writes a single read/write HDD head is able to physically do. – Mathieu Guindon Nov 11 '19 at 21:54

0 Answers0