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

C#

 
QuestionC# and XML Question Pin
seschu0118-Apr-06 4:35
seschu0118-Apr-06 4:35 
AnswerRe: C# and XML Question Pin
Robert Rohde18-Apr-06 5:33
Robert Rohde18-Apr-06 5:33 
AnswerRe: C# and XML Question Pin
LongRange.Shooter18-Apr-06 10:20
LongRange.Shooter18-Apr-06 10:20 
Questionpassing array byval versus byref Pin
bnathvbdotnet18-Apr-06 4:08
bnathvbdotnet18-Apr-06 4:08 
AnswerRe: passing array byval versus byref Pin
Judah Gabriel Himango18-Apr-06 4:50
sponsorJudah Gabriel Himango18-Apr-06 4:50 
AnswerRe: passing array byval versus byref Pin
Robert Rohde18-Apr-06 5:23
Robert Rohde18-Apr-06 5:23 
AnswerRe: passing array byval versus byref Pin
Guffa18-Apr-06 6:02
Guffa18-Apr-06 6:02 
QuestionI/O Threading Pin
eric_tran18-Apr-06 3:59
eric_tran18-Apr-06 3:59 
Please show your ability helping the following program

I use 2 threads, 1 read character from keyboard, 1 output 1 character at a time to console.

How can I pass values from Thread 1 to Thread 2? (I use boolean values but It doesnot work because Thread 2 takes only 1 object parameter)

Is there any other way of doing it?


using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
namespace  SS<br />
{<br />
    class Program<br />
    {<br />
        static string m1 = "\nType a string of text then press Enter. " +<br />
                 "Type '+' anywhere in the text to quit:\n";<br />
        static string m2 = "Character '{0}'";<br />
        static string m3 = "Character     ";<br />
        static char ch;<br />
        static int x;<br />
<br />
        static bool isM1 = false;<br />
        static bool isM2 = false;<br />
        static bool isM3 = false;<br />
<br />
        //static string input = "";<br />
        static void Main(string[] args)<br />
        {            <br />
             //x = Console.Read();                        <br />
            Console.WriteLine(m1);<br />
             <br />
<br />
            Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));<br />
            Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));<br />
<br />
            Console.WriteLine("Thread 1 starting...");<br />
            t1.Start(x);<br />
            Console.WriteLine("Thread 2 starting...");<br />
            t2.Start(x);<br />
<br />
            Thread.Sleep(80 * 1000);<br />
        }<br />
<br />
        public static void ReadInput(object param)<br />
        {     <br />
            int input = (int)param;            <br />
            <br />
            do<br />
            {<br />
                input = Console.Read();<br />
<br />
                try<br />
                {<br />
                    ch = Convert.ToChar(input);<br />
                    if (Char.IsWhiteSpace(ch))<br />
                    {<br />
                        //Console.WriteLine(m3, input);<br />
                        isM3 = true;<br />
                        if (ch == 0x0a)<br />
                            //Console.WriteLine(m1);<br />
                            isM1 = true;<br />
                    }<br />
                    else<br />
                        //Console.WriteLine(m2, ch, input);<br />
                        isM2 = true;<br />
                }<br />
                catch (OverflowException e)<br />
                {<br />
                    Console.WriteLine("{0} Value read = {1}.", e.Message, input);<br />
                    ch = Char.MinValue;<br />
                    Console.WriteLine(m1);<br />
                }<br />
            } while (ch != '+');<br />
<br />
            x = input;<br />
        }<br />
<br />
        public static void ReadOutput(object param1)<br />
        {<br />
            int output = (int)param1;<br />
            //bool isM2Bool = (bool)param2;<br />
       <br />
            if (isM3)<br />
            {<br />
                Console.WriteLine(m3, output);<br />
            }<br />
<br />
            if (isM1)<br />
            {<br />
                Console.WriteLine(m1);<br />
            }<br />
<br />
            if (isM2)<br />
            {<br />
                Console.WriteLine(m2, ch, output);<br />
            }<br />
            <br />
        }<br />
    }<br />
}<br />


eric
AnswerRe: I/O Threading Pin
Judah Gabriel Himango18-Apr-06 4:52
sponsorJudah Gabriel Himango18-Apr-06 4:52 
AnswerRe: I/O Threading Pin
Robert Rohde18-Apr-06 5:43
Robert Rohde18-Apr-06 5:43 
GeneralRe: I/O Threading Pin
eric_tran19-Apr-06 0:31
eric_tran19-Apr-06 0:31 
GeneralRe: I/O Threading Pin
eric_tran19-Apr-06 1:50
eric_tran19-Apr-06 1:50 
GeneralRe: I/O Threading Pin
Robert Rohde19-Apr-06 4:54
Robert Rohde19-Apr-06 4:54 
QuestionebXML message with C# Windows App Pin
Paul Brower18-Apr-06 2:54
Paul Brower18-Apr-06 2:54 
Questionhow to disable tree node in a dataset Pin
A4ad18-Apr-06 2:35
A4ad18-Apr-06 2:35 
AnswerRe: how to disable tree node in a dataset Pin
Robert Rohde18-Apr-06 5:47
Robert Rohde18-Apr-06 5:47 
GeneralRe: how to disable tree node in a dataset Pin
A4ad18-Apr-06 23:42
A4ad18-Apr-06 23:42 
Questionselect all the text in the textbox c# winform Pin
fady_sayegh18-Apr-06 2:19
fady_sayegh18-Apr-06 2:19 
AnswerRe: select all the text in the textbox c# winform Pin
Ed.Poore18-Apr-06 3:57
Ed.Poore18-Apr-06 3:57 
AnswerRe: select all the text in the textbox c# winform Pin
Eric Dahlvang18-Apr-06 4:52
Eric Dahlvang18-Apr-06 4:52 
AnswerRe: select all the text in the textbox c# winform Pin
Josh Smith18-Apr-06 5:25
Josh Smith18-Apr-06 5:25 
GeneralRe: select all the text in the textbox c# winform Pin
fady_sayegh18-Apr-06 6:27
fady_sayegh18-Apr-06 6:27 
AnswerRe: select all the text in the textbox c# winform Pin
LongRange.Shooter18-Apr-06 10:31
LongRange.Shooter18-Apr-06 10:31 
QuestionC# and Crystal Report Pin
Abhijeet Ballal18-Apr-06 1:16
Abhijeet Ballal18-Apr-06 1:16 
Questionworking with strings Pin
shezh18-Apr-06 0:42
shezh18-Apr-06 0:42 

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.