From fd4373645c4b23db08a3a00bfdecdb0961857ea2 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 29 May 2018 16:15:17 +0000 Subject: [PATCH] --- Testconsole/Program.cs | 165 ++++++++------------------------- Testconsole/Testconsole.csproj | 16 +++- 2 files changed, 53 insertions(+), 128 deletions(-) diff --git a/Testconsole/Program.cs b/Testconsole/Program.cs index 6fed906..2eea56a 100644 --- a/Testconsole/Program.cs +++ b/Testconsole/Program.cs @@ -1,136 +1,51 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System; -using System.Threading; -namespace Testconsole -{ - /*class Program - { - private class bla - { - public string Rb_charge_nr; - public string Rb_mat_nr; - public string Rb_kg_rohs; - public string Rb_eox_kg; - public string Rb_koh_kg; - public string Rb_milchs_kg; - public string Rb_essig_kg; - } - static void Main(string[] args) - { +namespace Testconsole { + class Program { + private Boolean RunningProcess = true; + private System.Threading.Thread sig_thread; - string strLine = "asdads,asdasd,asd,asd,asd,ads,a,sd,a,sd,as,d,asd,a,sd"; - bla a = new bla(); - try - { - string[] split = strLine.Split(','); - a.Rb_charge_nr = split[0]; - a.Rb_mat_nr = a.Rb_charge_nr.Substring(3, 3); - a.Rb_kg_rohs = split[1]; - a.Rb_eox_kg = split[2]; - a.Rb_koh_kg = split[3]; - a.Rb_milchs_kg = split[4]; - a.Rb_essig_kg = split[5]; - } - } - }*/ - // This example demonstrates the Console.Beep(Int32, Int32) method + public static void Main() => new Program(); + Program() { + Console.WriteLine("Start"); + this.WaitForShutdown(); + Console.WriteLine("Shutdown"); + Console.ReadLine(); + } -class Program -{ - public static void Main() - { -// Declare the first few notes of the song, "Mary Had A Little Lamb". - Note[] Mary = - { - new Note(Tone.B, Duration.QUARTER), - new Note(Tone.A, Duration.QUARTER), - new Note(Tone.GbelowC, Duration.QUARTER), - new Note(Tone.A, Duration.QUARTER), - new Note(Tone.B, Duration.QUARTER), - new Note(Tone.B, Duration.QUARTER), - new Note(Tone.B, Duration.HALF), - new Note(Tone.A, Duration.QUARTER), - new Note(Tone.A, Duration.QUARTER), - new Note(Tone.A, Duration.HALF), - new Note(Tone.B, Duration.QUARTER), - new Note(Tone.D, Duration.QUARTER), - new Note(Tone.D, Duration.HALF) + private void WaitForShutdown() { + this.sig_thread = new System.Threading.Thread(delegate () { + Console.WriteLine("Mono: Create thread"); + Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] { + new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM), + new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT) }; -// Play the song - Play(Mary); - } - -// Play the notes in a song. - protected static void Play(Note[] tune) - { - foreach (Note n in tune) - { - if (n.NoteTone == Tone.REST) - Thread.Sleep((int)n.NoteDuration); - else - Console.Beep((int)n.NoteTone, (int)n.NoteDuration); + Console.WriteLine("Mono: Set Signals"); + while (this.RunningProcess) { + Console.WriteLine("Mono: Wait for Signal"); + Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1); + Console.WriteLine("Mono: Signal Recieved: "+i); + this.RunningProcess = false; } + }); + if (Type.GetType("Mono.Runtime") != null) { + this.sig_thread.Start(); + } else { + Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown); + } + Console.WriteLine("Windows: Create Handler"); + Console.WriteLine("Wait"); + while (this.RunningProcess) { + System.Threading.Thread.Sleep(100); + } + Console.WriteLine("After Wait"); } -// Define the frequencies of notes in an octave, as well as -// silence (rest). - protected enum Tone - { - REST = 0, - GbelowC = 196, - A = 220, - Asharp = 233, - B = 247, - C = 262, - Csharp = 277, - D = 294, - Dsharp = 311, - E = 330, - F = 349, - Fsharp = 370, - G = 392, - Gsharp = 415, - } - -// Define the duration of a note in units of milliseconds. - protected enum Duration - { - WHOLE = 1600, - HALF = WHOLE/2, - QUARTER = HALF/2, - EIGHTH = QUARTER/2, - SIXTEENTH = EIGHTH/2, - } - -// Define a note as a frequency (tone) and the amount of -// time (duration) the note plays. - protected struct Note - { - Tone toneVal; - Duration durVal; - -// Define a constructor to create a specific note. - public Note(Tone frequency, Duration time) - { - toneVal = frequency; - durVal = time; - } - -// Define properties to return the note's tone and duration. - public Tone NoteTone { get{ return toneVal; } } - public Duration NoteDuration { get{ return durVal; } } + private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) { + e.Cancel = true; + Console.WriteLine("Windows get Signal"); + this.RunningProcess = false; } -} -/* -This example produces the following results: - -This example plays the first few notes of "Mary Had A Little Lamb" -through the console speaker. -*/ + } } diff --git a/Testconsole/Testconsole.csproj b/Testconsole/Testconsole.csproj index 8aed723..64de50f 100644 --- a/Testconsole/Testconsole.csproj +++ b/Testconsole/Testconsole.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,8 +9,11 @@ Properties Testconsole Testconsole - v4.5 + v4.7.1 512 + + + AnyCPU @@ -45,9 +48,16 @@ - + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + +