Click here to Skip to main content
15,886,026 members
Home / Discussions / C#
   

C#

 
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 
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 
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 static char ch;
           public static int x;

           public static bool isM1 ;
           public static bool isM2 ;
           public static 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
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 
AnswerRe: working with strings Pin
alexey N18-Apr-06 0:51
alexey N18-Apr-06 0:51 
AnswerRe: working with strings Pin
Stefan Troschuetz18-Apr-06 0:52
Stefan Troschuetz18-Apr-06 0:52 
GeneralRe: working with strings Pin
alexey N18-Apr-06 1:25
alexey N18-Apr-06 1:25 
GeneralRe: working with strings Pin
Stefan Troschuetz18-Apr-06 2:06
Stefan Troschuetz18-Apr-06 2:06 

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.