Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
AnswerRe: Any C# library for Forward error correction. Pin
Marco Bertschi25-Mar-13 6:17
protectorMarco Bertschi25-Mar-13 6:17 
AnswerRe: Any C# library for Forward error correction. Pin
unclepaul25-Mar-13 10:44
unclepaul25-Mar-13 10:44 
GeneralRe: Any C# library for Forward error correction. Pin
iamraghusunkara25-Mar-13 19:55
iamraghusunkara25-Mar-13 19:55 
QuestionRemote desktop using VNC Pin
superselector25-Mar-13 1:27
superselector25-Mar-13 1:27 
AnswerRe: Remote desktop using VNC Pin
Richard MacCutchan25-Mar-13 1:35
mveRichard MacCutchan25-Mar-13 1:35 
AnswerRe: Remote desktop using VNC Pin
Eddy Vluggen25-Mar-13 2:03
professionalEddy Vluggen25-Mar-13 2:03 
AnswerRe: Remote desktop using VNC Pin
Marco Bertschi25-Mar-13 6:22
protectorMarco Bertschi25-Mar-13 6:22 
Questiondelegate difficulty Pin
Member 993942324-Mar-13 21:45
Member 993942324-Mar-13 21:45 
Hello
here is a little difficulty:-
there is a program:- (source:pg 750: C# 4 Complete Reference by Herbert Schildt , McGrawHill )

  using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

//  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
namespace scratchpad3
{
    class Program
    {
        public static void Main()
        {
            int[] a = { 1, 2, 3, 4, 5 };
            MyThread mt1 = new MyThread("Child #1", a);
            MyThread mt2 = new MyThread("Child #2", a);
            mt1.Thrd.Join();
            mt2.Thrd.Join();
        }
    }

    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    class SumArray
    {
        int sum;
        object lockOn = new object(); // a private object to lock on
        public int SumIt(int[] nums)
        {
            lock (lockOn)
            { // lock the entire method
                sum = 0; // reset sum
                for (int i = 0; i < nums.Length; i++)
                {
                    sum += nums[i];
                    Console.WriteLine("Running total for " + Thread.CurrentThread.Name +  " is " + sum);
                    Console.Read();
                    Thread.Sleep(10); // allow task-switch
                }
                return sum;
            }
        }
    }

  //  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

class MyThread {
public Thread Thrd;
int[] a;
int answer;
// Create one SumArray object for all instances of MyThread.
static SumArray sa = new SumArray();
// Construct a new thread.
public MyThread(string name, int[] nums)
{
    a = nums;
    Thrd = new Thread(this.Run); // ****************************
    Thrd.Name = name;
    Thrd.Start(); // start the thread
}
// Begin execution of new thread.
void Run()
{
    Console.WriteLine(Thrd.Name + " starting.");
    answer = sa.SumIt(a);
    Console.WriteLine("Sum for " + Thrd.Name + " is " + answer);
    Console.WriteLine(Thrd.Name + " terminating.");
    Console.Read();
}
}
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

}


the o/p is given as;-

 Child #1 starting.
Running total for Child #1 is 1
Child #2 starting.
Running total for Child #1 is 3
Running total for Child #1 is 6
Running total for Child #1 is 10
Running total for Child #1 is 15
Running total for Child #2 is 1
Sum for Child #1 is 15
Child #1 terminating.
Running total for Child #2 is 3
Running total for Child #2 is 6
Running total for Child #2 is 10
Running total for Child #2 is 15
Sum for Child #2 is 15
Child #2 terminating.


My difficulty is at line that is starred
that line shows a delegate but you see in the form: Thrd = new Thread(this.Run);
shouldn't this be: Thrd = new Thread(this.Run()); ---- Is this a paradigm shift or ----????????????????????
AnswerRe: delegate difficulty Pin
Abhinav S24-Mar-13 22:29
Abhinav S24-Mar-13 22:29 
GeneralRe: delegate difficulty Pin
Member 993942325-Mar-13 3:42
Member 993942325-Mar-13 3:42 
GeneralRe: delegate difficulty Pin
PIEBALDconsult25-Mar-13 5:01
mvePIEBALDconsult25-Mar-13 5:01 
AnswerRe: delegate difficulty Pin
Paulo Zemek25-Mar-13 5:34
mvaPaulo Zemek25-Mar-13 5:34 
QuestionHow to use databindings class in web application? Pin
behrad kiani24-Mar-13 6:56
behrad kiani24-Mar-13 6:56 
AnswerRe: How to use databindings class in web application? Pin
Dave Kreskowiak24-Mar-13 7:33
mveDave Kreskowiak24-Mar-13 7:33 
AnswerRe: How to use databindings class in web application? Pin
Eddy Vluggen24-Mar-13 23:33
professionalEddy Vluggen24-Mar-13 23:33 
Questionwebcam based credit card reader with face recognition Pin
nabil j24-Mar-13 5:44
nabil j24-Mar-13 5:44 
AnswerRe: webcam based credit card reader with face recognition Pin
OriginalGriff24-Mar-13 5:52
mveOriginalGriff24-Mar-13 5:52 
GeneralRe: webcam based credit card reader with face recognition Pin
Narasimharao Chebrolu16-Nov-21 19:48
Narasimharao Chebrolu16-Nov-21 19:48 
AnswerRe: webcam based credit card reader with face recognition Pin
DaveyM6925-Mar-13 1:10
professionalDaveyM6925-Mar-13 1:10 
AnswerRe: webcam based credit card reader with face recognition Pin
Narasimharao Chebrolu16-Nov-21 19:48
Narasimharao Chebrolu16-Nov-21 19:48 
Questionhow to access specefic attribute of a table? Pin
behrad kiani23-Mar-13 23:42
behrad kiani23-Mar-13 23:42 
AnswerRe: how to access specefic attribute of a table? Pin
Mycroft Holmes24-Mar-13 2:23
professionalMycroft Holmes24-Mar-13 2:23 
AnswerRe: how to access specefic attribute of a table? Pin
Dave Kreskowiak24-Mar-13 5:38
mveDave Kreskowiak24-Mar-13 5:38 
GeneralRe: how to access specefic attribute of a table? Pin
behrad kiani24-Mar-13 6:06
behrad kiani24-Mar-13 6:06 
GeneralRe: how to access specefic attribute of a table? Pin
Dave Kreskowiak24-Mar-13 6:50
mveDave Kreskowiak24-Mar-13 6:50 

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.