Wednesday, March 07, 2018

Useful Tools and Settings for Visual Studio

Tools -> Options:

Environment -> InternationalSettings

Language

Environment -> General

Color Theme Dark

Environment -> Fonts & Colors -> Inactive Selected Item

xaml editor better visible

Projects and Solutions –> General

Track Active Item in Solution Explorer

TextEditor -> c# -> Advanced

Outlining - Collapse #regions when collapsing to definitions



Tools:

Match Margin: 
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MatchMargin


Monday, March 05, 2018

WinForm bei Bedarf in Gui Task zurück

wichtig: Gui im Gui Thread öffnen !

        /// <summary>
        /// 1) check if correct thread, if not call in correct thread
        /// 2) sets Text of Control c
        /// </summary>
        /// <param name="c"></param>
        /// <param name="text"></param>
        public void _SetText(Control c, string text)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<Control, string>(_SetText), c, text);
            else
                c.Text = text;
        }



        public void _SetMax(int max)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<int>(_SetMax),max);
            else
                progressBar1.Maximum = max;
        }

        public void _IncProgressBar()
        {
            if (this.InvokeRequired)
                this.Invoke(new Action(_IncProgressBar));
            else
                progressBar1.Value += 1;
        }

longrunning c# Task mit Fehlerbehandlung

                var t = new Task(() => { ImportFile(tablename, conStr, ofd.FileName); },TaskCreationOptions.LongRunning);
                var nextTask = t.ContinueWith(antecedent =>
                {
                    if (antecedent.IsFaulted)
                    {
                        PLog.ShowAndLogError("SqlTools.ImportFile Error: " + antecedent?.Exception?.Message +antecedent?.Exception?.InnerException?.Message);
                    }
                    else if (antecedent.IsCanceled)
                    {
                        PLog.LogWarning("SqlTools.ImportFile Canceled: ");
                    }
                    else
                    {
                        PLog.LogInfo("SqlTools.ImportFile succeeded ! ");
                    }
                });
                t.Start();