Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6184447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:32:12+00:00 2026-05-24T01:32:12+00:00

I can’t say i fully understood the concept of threads even i read so

  • 0

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.

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..

Oh btw the output of this code is usually 3 threads working with the latest parameter (which is configurations for 200p)

The code i use to call my thread is this;

    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 >= 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 => 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 => 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 + "\"";
    }

And code to my thread Class is this;

    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();
    }
}

Thanks in advance any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:32:14+00:00Added an answer on May 24, 2026 at 1:32 am

    The issue is that you are “capturing” initargs via the use of the lambda expression.

    You shouldn’t be reusing initargs in this way. Your code will be more readable and easier to maintain, and you will avoid this problem.

    So, first, use two different instances of initargs:

    string initArgsWithScaleTwo = // 
    ThreadPool.QueueUserWorkItem(o => pt.callExecute(initArgsWithScaleTwo));
    string initArgsWithScaleFour = //
    ThreadPool.QueueUserWorkItem(o => pt.callExecute(initArgsWithScaleFour));    
    

    Second, there’s a lot of needless repetition when you assign to initArgs. That’s not fun to maintain. This should get you started on a clearer version:

    private string GetInitArgs(
        string filePath,
        int scale,
        int newHeight,
        string vidPathHigh,
        int scanLines
    ) {
        return "-i " + filePath + String.Format(" -vcodec wmv2 -qscale {0} -s ", scale) + newHeight + String.Format("x{0} -acodec wmav2 -ar 44100 -ab 128k -y \"" + pt.vidPathHigh + "\"", scanLines);
    }
    

    You can do more and use String.Format to really clean the whole thing up.

    Then you can say

    string initArgsWithScaleTwoAnd480ScanLines = 
        GetInitArgs(
           pt.filePath,
           2,
           (int)Math.Floor(480 * aspectRatio,
           pt.vidPathHigh,
           480
        );
    

    All that said, I don’t understand why you are using threads at all if the threads are merely starting new processes. Just start the processes directly, and wait for them all to finish.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I order my users in the database, so I don't have to say
I want to count how many characters a certain string has in PHP, but
Can someone guide me on a possible solution? I don't want to use /bin/cp
Can you guys help me understand a concept real quick, I'm having trouble understanding
Can anyone let me know how can we change the value of kendo combobox
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can I authenticate with just Google account username and password instead of using OAuth?
Can any one tell, how to get the result of LINQ query contains group
Can we change the default action of the edit selected row button? Here is
Can someone thoroughly explain the last line of the following code: def myMethod(self): #

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.