Click here to Skip to main content
15,887,404 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 0:00
mveOriginalGriff3-Feb-11 0:00 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 1:02
All Time Programming3-Feb-11 1:02 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 1:11
mveOriginalGriff3-Feb-11 1:11 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 1:24
All Time Programming3-Feb-11 1:24 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 1:30
mveOriginalGriff3-Feb-11 1:30 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 2:02
All Time Programming3-Feb-11 2:02 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 2:30
mveOriginalGriff3-Feb-11 2:30 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 2:49
All Time Programming3-Feb-11 2:49 
Both are of different solutions.

But yes, realized during debugging & removed the errorMsg = "" & connected = false lines. And now I see that errorMsg has value in it.

Implementaion PART :
                    try
                    {
                        //conThread = new Thread(new ThreadStart(StartConnect));
                        //conThread.Start();
                        StartConnect();
                    }
                    catch (ThreadAbortException te)
                    {
                        Console.WriteLine("Abort Exception CAUGHT");
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                        if (msg.Equals("NotConnectedException"))
                            MessageBox.Show("Error connecting to the Server : Connection Time Out \n Unable to connect to the Server", "Time Out", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        else if (msg.IndexOf("Cannot load CA certificate file") > 0)
                            MessageBox.Show("Error connecting to the Server : Problem with Certificate File \n Unable to Load or Find required Certificate file.", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        else if (msg.IndexOf("Error opening 'Auth' auth file:") > 0)
                            MessageBox.Show("Error connecting to the Server : Problem with Authentication File \n Unable to Load or Find required Authentication file.", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        else if (msg.IndexOf("Error opening configuration file:") > 0)
                            MessageBox.Show("Error connecting to the Server : Problem with Configuration File \n Unable to find required Configuration file.", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        else
                            MessageBox.Show("Error connecting to the Server : \n " + msg, "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    finally
                    {
                        //conThread.Abort();                        
                        //Console.WriteLine("Thread ISAlive = " + conThread.IsAlive);
                    }                    
                      
                    Console.WriteLine("Execution Completed ");
//**************

        private void StartConnect()
        {
            DateTime start = DateTime.Now;

            int timeout = 100000, timepassed = 0;
            
            oc = new OpenConnect(cmd, timeout);
            int retVal = oc.ConnectToServer();
            while (!oc.Connected)
            {
                timepassed = (int)(DateTime.Now - start).TotalMilliseconds;
                if (timepassed > timeout)
                {
                    oc.DisconnectServer();
                    connectedToVpn = false;
                    throw new Exception("NotConnectedException");
                } else if (oc.ErrorMessage.Length > 0)
                {
                    Console.WriteLine("ERROR MESAGE = " + oc.ErrorMessage);  // THIS IS PRINTED
                    oc.DisconnectServer();
                    Console.WriteLine("DISCONNECTED");    // THIS IS PRINTED
                    connectedToVpn = false;
                    throw new Exception(oc.ErrorMessage);  // BUT THIS IS NEVER THROWN
                    Console.WriteLine("THROWN");
                }
                Thread.Sleep(100);
            }
            return;
        }


iT THROWS "NotConnectedException" exception when the time is over.
The OUTPUT :
LINE = Thu Feb 03 19:07:10 2011 Cannot load CA certificate file........
ERROR MESAGE = Thu Feb 03 19:07:10 2011 Cannot load CA certificate file ......
LINE = Thu Feb 03 19:07:10 2011 Exiting
DISCONNECTED
/// SEE MSGBOX OF TIME OUT I.E. OF NotConnectedException
Execution Completed

Why it doesn't throw that exception of error message ?
I ran without debugging also, increased the timeout duration, yet it waits hlds itself and throws Time out Exception only.
What can be the problem for this ?

Thanks & Regards,


GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 3:01
mveOriginalGriff3-Feb-11 3:01 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 3:17
All Time Programming3-Feb-11 3:17 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 2:56
All Time Programming3-Feb-11 2:56 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 3:06
mveOriginalGriff3-Feb-11 3:06 
GeneralRe: How to run a Command and retrieve data from it ? [modified] Pin
All Time Programming3-Feb-11 3:27
All Time Programming3-Feb-11 3:27 
AnswerRe: How to run a Command and retrieve data from it ? Pin
PIEBALDconsult3-Feb-11 1:44
mvePIEBALDconsult3-Feb-11 1:44 
QuestionPrint Settings for ReportViewer pogrammatically Pin
freshonlineMax2-Feb-11 18:24
freshonlineMax2-Feb-11 18:24 
GeneralRe: Print Settings for ReportViewer pogrammatically Pin
Praveen Raghuvanshi2-Feb-11 19:07
professionalPraveen Raghuvanshi2-Feb-11 19:07 
GeneralRe: Print Settings for ReportViewer pogrammatically Pin
freshonlineMax2-Feb-11 19:46
freshonlineMax2-Feb-11 19:46 
Question[Solved] Drag'N'Drop to and on control [modified] Pin
lukeer2-Feb-11 4:04
lukeer2-Feb-11 4:04 
AnswerRe: Drag'N'Drop to and on control Pin
Henry Minute2-Feb-11 9:25
Henry Minute2-Feb-11 9:25 
GeneralRe: Drag'N'Drop to and on control Pin
lukeer4-Feb-11 0:17
lukeer4-Feb-11 0:17 
Questionbound datagridview new row problem Pin
Erdinc272-Feb-11 2:22
Erdinc272-Feb-11 2:22 
AnswerRe: bound datagridview new row problem Pin
Not Active2-Feb-11 3:47
mentorNot Active2-Feb-11 3:47 
GeneralRe: bound datagridview new row problem Pin
Erdinc272-Feb-11 4:13
Erdinc272-Feb-11 4:13 
GeneralRe: bound datagridview new row problem Pin
Not Active2-Feb-11 14:57
mentorNot Active2-Feb-11 14:57 
GeneralRe: bound datagridview new row problem Pin
Erdinc272-Feb-11 20:48
Erdinc272-Feb-11 20:48 

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.