Click here to Skip to main content
15,881,204 members
Home / Discussions / C#
   

C#

 
AnswerRe: Write audio to USB Modem via COM Port Pin
OriginalGriff4-Nov-17 23:35
mveOriginalGriff4-Nov-17 23:35 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 0:57
ManojKumarShah20175-Nov-17 0:57 
GeneralRe: Write audio to USB Modem via COM Port Pin
OriginalGriff5-Nov-17 1:05
mveOriginalGriff5-Nov-17 1:05 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 2:31
ManojKumarShah20175-Nov-17 2:31 
GeneralRe: Write audio to USB Modem via COM Port Pin
OriginalGriff5-Nov-17 2:40
mveOriginalGriff5-Nov-17 2:40 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 3:46
ManojKumarShah20175-Nov-17 3:46 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 4:10
ManojKumarShah20175-Nov-17 4:10 
QuestionMultithreaded function calls Pin
Kenneth Haugland4-Nov-17 4:41
mvaKenneth Haugland4-Nov-17 4:41 
Assume that I have a pipe that consists of sections of variable radiuses and that I want to make calculations at different frequencies. So I want the calculations done at different threads for each frequency, but the list of pipe sections stays the same.
public class PipeSection
{
    public PipeSection(double radius)
    {
        this.Radius = radius;
    }

    public double Radius { get; set; }


    public double Calculate(double Frequency)
    {
        return Frequency * this.Radius;
    }

}

To run the frequencies in parallel I use Rx:
CancellationTokenSource ctr = new CancellationTokenSource();
       List<PipeSection> wn = new List<PipeSection>();

       public MainWindow()
       {
           InitializeComponent();

           PipeSection[] input = { new PipeSection(5), new PipeSection(6), new PipeSection(7) };

           wn.AddRange(input);

           //Calcualte at the frequencies 0,100,2000,3000
           var FreqData = new double[] { 0, 100, 2000, 3000 }.ToObservable<double>();

           FreqData
               //Off the ui thread
               .ObserveOn(Scheduler.Default)
               //Run each thread seperatly
               .SelectMany(x => Task.Run<double>(() => DoCalcualtions(x,wn), ctr.Token))
               //Back to the UI thread
               .ObserveOnDispatcher()
               //Subscribe and start the calcualtions
               .Subscribe(args => {
                                   //Update the progressbar when a thread is completed
                                   pgbProgress.Value += 1;
                                   //Tell me what thread is completed
                                   txtText.Text += Environment.NewLine + args.ToString();
                                   },
                           () => {
                                   //All done, here I could do sorting etc.
                                   txtText.Text += Environment.NewLine + "All done";
                                 }
                           );
       }

       private double DoCalcualtions(double Freq, List<PipeSection> input)
       {
           double result=1;
           for (int i = 0; i < input.Count(); i++)
               result *= input[i].Calculate(Freq);

           return result;
       }

This does compile and run, but I have some questions regarding if the multithread calls:
1) Will I have to clone my list of Pipesections for each frequency (i.a. for each thread I want to run) ?
2) Can the DoCalcualtion function now be accessed in parallel or will I have to move it inside the PipeSection class to ensure this?
3) Is there a much better way of doing this?

-Kenneth
AnswerRe: Multithreaded function calls Pin
Sascha Lefèvre4-Nov-17 6:13
professionalSascha Lefèvre4-Nov-17 6:13 
GeneralRe: Multithreaded function calls Pin
Kenneth Haugland4-Nov-17 6:49
mvaKenneth Haugland4-Nov-17 6:49 
GeneralRe: Multithreaded function calls Pin
Sascha Lefèvre4-Nov-17 7:01
professionalSascha Lefèvre4-Nov-17 7:01 
GeneralRe: Multithreaded function calls Pin
Kenneth Haugland4-Nov-17 7:10
mvaKenneth Haugland4-Nov-17 7:10 
GeneralRe: Multithreaded function calls Pin
Sascha Lefèvre4-Nov-17 7:23
professionalSascha Lefèvre4-Nov-17 7:23 
QuestionHow to make the ListView to display each thumbnail immediately after it's loaded? [solved] Pin
alin14-Nov-17 3:02
alin14-Nov-17 3:02 
AnswerRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Dave Kreskowiak4-Nov-17 3:49
mveDave Kreskowiak4-Nov-17 3:49 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 3:51
alin14-Nov-17 3:51 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Dave Kreskowiak4-Nov-17 4:17
mveDave Kreskowiak4-Nov-17 4:17 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 4:06
alin14-Nov-17 4:06 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Dave Kreskowiak4-Nov-17 4:19
mveDave Kreskowiak4-Nov-17 4:19 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 5:57
alin14-Nov-17 5:57 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 6:27
professionalSascha Lefèvre4-Nov-17 6:27 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:05
alin14-Nov-17 7:05 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:13
professionalSascha Lefèvre4-Nov-17 7:13 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:22
alin14-Nov-17 7:22 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:25
professionalSascha Lefèvre4-Nov-17 7:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.