Click here to Skip to main content
15,949,686 members
Home / Discussions / C#
   

C#

 
QuestionBluetooth in C# Pin
hschutte19-Apr-06 2:21
hschutte19-Apr-06 2:21 
AnswerRe: Bluetooth in C# Pin
LongRange.Shooter19-Apr-06 3:24
LongRange.Shooter19-Apr-06 3:24 
QuestionHTMLdocument and Webclient/Webbrowser Pin
ranzask19-Apr-06 2:12
ranzask19-Apr-06 2:12 
AnswerRe: HTMLdocument and Webclient/Webbrowser Pin
Ed.Poore19-Apr-06 9:19
Ed.Poore19-Apr-06 9:19 
AnswerRe: HTMLdocument and Webclient/Webbrowser Pin
Ravi Bhavnani19-Apr-06 9:26
professionalRavi Bhavnani19-Apr-06 9:26 
GeneralRe: HTMLdocument and Webclient/Webbrowser Pin
ranzask19-Apr-06 9:40
ranzask19-Apr-06 9:40 
GeneralRe: HTMLdocument and Webclient/Webbrowser Pin
Ravi Bhavnani19-Apr-06 9:47
professionalRavi Bhavnani19-Apr-06 9:47 
QuestionThreading program Pin
eric_tran19-Apr-06 1:52
eric_tran19-Apr-06 1:52 
I've got a problem.
How can I pass variables from ReadInput function to ReadOutput function via struct?

Please help.



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

namespace ConsoleApplication9
{
    class Program
    {
        static string m1 = "\nType a string of text then press Enter. " +
                 "Type '+' anywhere in the text to quit:\n";
        static string m2 = "Character '{0}'";
        static string m3 = "Character     ";

        public  struct ThreadFuncParameters
        {
           public   char ch;
           public   int x;

           public   bool isM1 ;
           public   bool isM2 ;
           public   bool isM3 ;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(m1);

               ThreadFuncParameters pas = new ThreadFuncParameters();
               pas.ch = 'a' ;
               pas.x = 0;
               pas.isM1 = false;
               pas.isM2 = false;
               pas.isM3 = false;

               Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));
               Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));

               Console.WriteLine("Thread 1 starting...");
               t1.Start(pas);
               Console.WriteLine("Thread 2 starting...");
               t2.Start(pas);

               //Thread.Sleep(80 * 1000);
        }


        public static void ReadInput(object paramALL)
        {
                ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
                char p1 = par.ch;
                int p2 = par.x;
                bool p3 = par.isM1;
                bool p4 = par.isM2;
                bool p5 = par.isM3;

            do
            {
                p2 = Console.Read();

                try
                {
                    p1 = Convert.ToChar(p2);
                    if (Char.IsWhiteSpace(p1))
                    {
                        //Console.WriteLine(m3, input);
                        p5 = true;
                        if (p1== 0x0a)
                            //Console.WriteLine(m1);
                            p3= true;
                    }
                    else
                        //Console.WriteLine(m2, ch, input);
                        p4 = true;
                }
                catch (OverflowException e)
                {
                    Console.WriteLine("{0} Value read = {1}.", e.Message, p2);
                    p1 = Char.MinValue;
                    Console.WriteLine(m1);
                }
            } while (p1!= '+');


            ch = p1;
            x = p2;
            isM1 = p3;
            isM2 = p4;
            isM3 = p5;
        }


        public static void ReadOutput(object paramALL)
        {
            ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
            char p1 = par.ch;
            int p2 = par.x;
            bool p3 = par.isM1;
            bool p4 = par.isM2;
            bool p5 = par.isM3;

            //int output = (int)param1;
            //bool isM2Bool = (bool)param2;

            if (p5)
            {
                Console.WriteLine(m3, p2);
            }

            if (p3)
            {
                Console.WriteLine(m1);
            }

            if (p4)
            {
                Console.WriteLine(m2, p1, p2);
            }

        }
    }
}



eric

-- modified at 7:54 Wednesday 19th April, 2006
AnswerRe: Threading program Pin
LongRange.Shooter19-Apr-06 5:26
LongRange.Shooter19-Apr-06 5:26 
GeneralRe: Threading program Pin
eric_tran19-Apr-06 5:48
eric_tran19-Apr-06 5:48 
QuestionUninstall link in deployment project Pin
Stefan Troschuetz19-Apr-06 1:41
Stefan Troschuetz19-Apr-06 1:41 
Questiondiscusiion forum Pin
prgramya19-Apr-06 1:41
prgramya19-Apr-06 1:41 
AnswerRe: discusiion forum Pin
J4amieC19-Apr-06 2:36
J4amieC19-Apr-06 2:36 
AnswerRe: discusiion forum Pin
LongRange.Shooter19-Apr-06 3:57
LongRange.Shooter19-Apr-06 3:57 
QuestionDetect when new application opened? Pin
Werner Vos19-Apr-06 1:32
Werner Vos19-Apr-06 1:32 
QuestionDirectoryNotFoundException when directory does exist Pin
sergestusxx19-Apr-06 1:19
sergestusxx19-Apr-06 1:19 
AnswerRe: DirectoryNotFoundException when directory does exist Pin
mav.northwind19-Apr-06 2:00
mav.northwind19-Apr-06 2:00 
AnswerRe: DirectoryNotFoundException when directory does exist Pin
LongRange.Shooter19-Apr-06 4:02
LongRange.Shooter19-Apr-06 4:02 
AnswerRe: DirectoryNotFoundException when directory does exist Pin
theDexter19-Apr-06 8:50
theDexter19-Apr-06 8:50 
GeneralRe: DirectoryNotFoundException when directory does exist Pin
sergestusxx19-Apr-06 9:29
sergestusxx19-Apr-06 9:29 
QuestionRegarding WEB TV Pin
veerasekar Muthiah19-Apr-06 0:27
veerasekar Muthiah19-Apr-06 0:27 
AnswerRe: Regarding WEB TV Pin
LongRange.Shooter19-Apr-06 4:13
LongRange.Shooter19-Apr-06 4:13 
QuestionWindows Form Datagrid ? Pin
Gammaza19-Apr-06 0:24
Gammaza19-Apr-06 0:24 
QuestionSystem.Nullable(of Short) - How do I pass Null ... Pin
MaWeRic19-Apr-06 0:06
MaWeRic19-Apr-06 0:06 
AnswerRe: System.Nullable(of Short) - How do I pass Null ... Pin
Jon Hulatt19-Apr-06 0:35
Jon Hulatt19-Apr-06 0:35 

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.