Note that there are some explanatory texts on larger screens.

plurals
  1. POSustaining parameter values in multi threads that are created dynamically? (C#)
    text
    copied!<p>I can't say i fully understood the concept of threads even i read so many articles over it, i'm a bit thick and what i want is thread safe parameters. I'm sending string arguments to a thread that i'm using ThreadPool.QueueUserWorkItem to start but i'm using the same thread just after it again with another arguments.</p> <p>What i want from it to be able to process different threads with different arguments but its not stable probably because i'm changing the parameter string just after calling the first thread. My instincts tell me to use Lock but don't know how to and where..</p> <p>Oh btw the output of this code is usually 3 threads working with the latest parameter (which is configurations for 200p)</p> <p>The code i use to call my thread is this;</p> <pre><code> processThread pt = new processThread(); pt.fileName = AppDomain.CurrentDomain.BaseDirectory + "bin\\ffmpeg.exe"; pt.filePath = Path.Combine(Vci.Core.Sandbox.UploaderControlSandboxPath, fileGuid); pt.vidPathHigh = AppDomain.CurrentDomain.BaseDirectory + "videos\\480p\\" + fileGuid + ".wmv"; pt.vidPathMid = AppDomain.CurrentDomain.BaseDirectory + "videos\\360p\\" + fileGuid + ".wmv"; pt.vidPathLow = AppDomain.CurrentDomain.BaseDirectory + "videos\\200p\\" + fileGuid + ".wmv"; if (height &gt;= 480) { newHeight = (int)Math.Floor(480 * aspectRatio); initArgs = "-i " + pt.filePath + " -vcodec wmv2 -qscale 2 -s " + newHeight + "x480 -acodec wmav2 -ar 44100 -ab 128k -y \"" + pt.vidPathHigh + "\""; ThreadPool.QueueUserWorkItem(o =&gt; pt.callExecute(initArgs)); newHeight = (int)Math.Floor(360 * aspectRatio); initArgs = "-i " + pt.filePath + " -vcodec wmv2 -qscale 4 -s " + newHeight + "x360 -acodec wmav2 -ar 44100 -ab 128k -y \"" + pt.vidPathMid + "\""; ThreadPool.QueueUserWorkItem(o =&gt; pt.callExecute(initArgs)); newHeight = (int)Math.Floor(200 * aspectRatio); initArgs = "-i " + pt.filePath + " -vcodec wmv2 -qscale 6 -s " + newHeight + "x200 -acodec wmav2 -ar 44100 -ab 128k -y \"" + pt.vidPathLow + "\""; } </code></pre> <p>And code to my thread Class is this;</p> <pre><code> public class processThread { public string filePath { get; set; } public string fileName { get; set; } public string vidPathHigh { get; set; } public string vidPathMid { get; set; } public string vidPathLow { get; set; } public void callExecute(Object o) { try { executeProcess(fileName, o as string); } catch (ThreadAbortException abortException) { // do something } } private void executeProcess(string fileName, string arguments) { Process myProcess = new Process(); myProcess.StartInfo.FileName = fileName; myProcess.StartInfo.Arguments = arguments; myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.CreateNoWindow = false; myProcess.StartInfo.RedirectStandardOutput = false; try { myProcess.Start(); } catch (Exception ex) { throw; } myProcess.WaitForExit(); myProcess.Close(); } } </code></pre> <p>Thanks in advance any help is appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload