Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program which transcodes audio submits tasks to a multithreaded service but no intensive tasks are proformed by my program, i have a class and a method which submits the conversion task Extract the audio > Submit the job > Wait until its finished

I want to run this method multiple times without the class values conflicting

Ive tried declaring a new instance of the class and running it with a backgroundworker like this

new ConversionProcess(Files);
                    var Slot1 = new BackgroundWorker();
                    Slot1.DoWork += ConversionProcess.Convert;
                    Slot1.RunWorkerAsync();  


This works for one instance but if i create a new instance and run it in another backgroundworker only the first instance runs.
Is there any way of doing this in c#

--class
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

namespace AudioThreadingTest
{
    public class ConversionProcess
    {
        private static List<string> FileList;
        public static string AudioChannels;

        public ConversionProcess(List<string> ConstructorFileList)
        {
            FileList = ConstructorFileList;
        }

        public static void Convert(object Sender, DoWorkEventArgs DoWorkEventArgs)
        {
            foreach (var FileName in FileList)
            {
            new SourceHandler();
            new MP4Multiplexer();
            new ConversionLog();
            new JobEvaluate();
            new AACTranscoder();
            SourceHandler.GetStreamNames(FileName);
            SourceHandler.ExtractStreams(FileName);
            ConversionLog.AddToLog("Finished Extracting Source File.");
            AACTranscoder.CompressAudio(Stream);
            MP4Multiplexer.PackageMp4();
            }
        }
    }
}
Posted
Updated 31-Mar-12 10:35am
v3
Comments
Shahin Khorshidnia 31-Mar-12 15:28pm    
Let's see the class code
fct2004 31-Mar-12 21:47pm    
What version of .Net is this in?

Hello

I haven't gotten any problem except that:
The class is not "Threadsafe" since being static fileds like that. You shoud lock FileList
Please consider the link for more information about Threadsafe: MSDN

And this:
http://msdn.microsoft.com/en-us/library/dd997305.aspx[^]


And:
What is 'thread safty'?

If I haven't understood your intention, then let's know more about (object Sender, DoWorkEventArgs DoWorkEventArgs)
What is the handler method of Slot1.DoWork += ConversionProcess.Convert ?
 
Share this answer
 
v6
If I understand your question right, I think you only want to run one at time. What I would recommend is that you run the next instance from the BackgroundWorker completed event. You can also run it at the end of the current BackgroundWorker, but that would require including the information for running the BackgroundWorker to be included in the arguments passed to the BackgroundWorkder.

Another note: include any information needed by the BackgroundWorking in the object being passed when doing the run method.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900