Click here to Skip to main content
15,904,346 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to use switch case instead of if statements? Pin
Richard Deeming12-Jun-23 1:06
mveRichard Deeming12-Jun-23 1:06 
AnswerRe: How to use switch case instead of if statements? Pin
jschell12-Jun-23 11:09
jschell12-Jun-23 11:09 
QuestionClean code in C# development Pin
WeiminYu10-Jun-23 18:27
WeiminYu10-Jun-23 18:27 
AnswerRe: Clean code in C# development Pin
OriginalGriff10-Jun-23 18:31
mveOriginalGriff10-Jun-23 18:31 
GeneralRe: Clean code in C# development Pin
Richard Andrew x6411-Jun-23 7:17
professionalRichard Andrew x6411-Jun-23 7:17 
GeneralRe: Clean code in C# development Pin
OriginalGriff11-Jun-23 8:32
mveOriginalGriff11-Jun-23 8:32 
GeneralRe: Clean code in C# development Pin
trønderen11-Jun-23 11:20
trønderen11-Jun-23 11:20 
QuestionGetting Google Contacts Pin
Kevin Marois6-Jun-23 16:46
professionalKevin Marois6-Jun-23 16:46 
AnswerRe: Getting Google Contacts Pin
OriginalGriff6-Jun-23 18:47
mveOriginalGriff6-Jun-23 18:47 
GeneralRe: Getting Google Contacts Pin
Kevin Marois7-Jun-23 5:51
professionalKevin Marois7-Jun-23 5:51 
AnswerRe: Getting Google Contacts Pin
Richard MacCutchan6-Jun-23 22:02
mveRichard MacCutchan6-Jun-23 22:02 
GeneralRe: Getting Google Contacts Pin
jschell7-Jun-23 5:19
jschell7-Jun-23 5:19 
GeneralRe: Getting Google Contacts Pin
Richard MacCutchan7-Jun-23 5:42
mveRichard MacCutchan7-Jun-23 5:42 
GeneralRe: Getting Google Contacts Pin
Kevin Marois7-Jun-23 5:53
professionalKevin Marois7-Jun-23 5:53 
GeneralRe: Getting Google Contacts Pin
Richard MacCutchan7-Jun-23 6:09
mveRichard MacCutchan7-Jun-23 6:09 
GeneralRe: Getting Google Contacts Pin
Kevin Marois7-Jun-23 7:00
professionalKevin Marois7-Jun-23 7:00 
GeneralRe: Getting Google Contacts Pin
jschell8-Jun-23 6:53
jschell8-Jun-23 6:53 
GeneralRe: Getting Google Contacts Pin
Richard MacCutchan8-Jun-23 8:01
mveRichard MacCutchan8-Jun-23 8:01 
AnswerRe: Getting Google Contacts Pin
OriginalGriff6-Jun-23 23:33
mveOriginalGriff6-Jun-23 23:33 
AnswerRe: Getting Google Contacts Pin
Gerry Schmitz7-Jun-23 3:24
mveGerry Schmitz7-Jun-23 3:24 
QuestionProcess.Start() Default Browser and Detect Close Pin
Kevin Marois6-Jun-23 13:46
professionalKevin Marois6-Jun-23 13:46 
AnswerRe: Process.Start() Default Browser and Detect Close Pin
Richard Andrew x646-Jun-23 14:56
professionalRichard Andrew x646-Jun-23 14:56 
GeneralRe: Process.Start() Default Browser and Detect Close Pin
Kevin Marois6-Jun-23 17:07
professionalKevin Marois6-Jun-23 17:07 
Thanks. I set EnableRaisingEvents and it fires the event, however it fires right away as soon as Process.Start() is called. I'm hoping to handle the user closing the default browser.

I saw that page earlier. I have one question on that.

I want to open the default browser and wait for the user to close it. In this code I would have to specifically specify what browser I want.
public class Program
{
    private static Process myProcess;
    private static TaskCompletionSource eventHandled;

    public static void Main(string[] args)
    {
        StartProcess();

        Console.ReadLine();
    }

    private static async Task StartProcess()
    {
        eventHandled = new TaskCompletionSource();

        using (myProcess = new Process())
        {
            try
            {
                myProcess.StartInfo.FileName = "chrome";
                myProcess.EnableRaisingEvents = true;
                myProcess.Exited += new EventHandler(myProcess_Exited);
                myProcess.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            await Task.WhenAny(eventHandled.Task, Task.Delay(30000));
        }
    }

    private static void myProcess_Exited(object sender, System.EventArgs e)
    {
        Console.WriteLine("Process exited");
        eventHandled.TrySetResult(true);
    }
}
Setting
"myProcess.StartInfo.FileName = "www.codeproject.com";"
throws an exception because that's looking for a exe to run.
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.

AnswerRe: Process.Start() Default Browser and Detect Close Pin
Richard Deeming6-Jun-23 21:46
mveRichard Deeming6-Jun-23 21:46 
AnswerRe: Process.Start() Default Browser and Detect Close Pin
jschell7-Jun-23 5:23
jschell7-Jun-23 5:23 

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.