Full Trust European Hosting

BLOG about Full Trust Hosting and Its Technology - Dedicated to European Windows Hosting Customer

European Visual Studio 2017 Hosting - HostForLIFE.eu :: Drawing rubber-band lines and shapes in VB.NET

clock June 19, 2020 12:57 by author Peter

 The lack of XOR Drawing feature in GDI+ was not certainly welcome in the programmer's community. I guess it will be hard to survive with this handicap. In spite of this, I would like to show how we can draw rubber-band lines and shapes in GDI+ with just a few lines of code.

     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim size As Size = SystemInformation.PrimaryMonitorMaximizedWindowSize 
    bitmap = New Bitmap(size.Width, size.Height) 
    gB = Graphics.FromImage(bitmap) 
    Dim bckColor As Color = Me.BackColor 
    gB.Clear(bckColor) 
    End Sub 
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) 
    Dim p As Point = New Point(e.X, e.Y) 
    x0 = p.X 
    y0 = p.Y 
    drag = True 
    End Sub 
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) 
    Dim p As Point = New Point(e.X, e.Y) 
    x= p.X 
    y = p.Y 
    Dim cx As Integer = x - x0 
    Dim cy As Integer = y - y0 
    If drag Then 
    Dim gx As Graphics = CreateGraphics() 
    gx.DrawImage(bitmap, 0, 0) 
    gx.Dispose() 
    Dim g As Graphics = CreateGraphics() 
    Dim pen As Pen = New Pen(Color.Blue) 
    Select Case DrawMode 
    Case 1 
    g.DrawLine(pen, x0, y0, x, y) 
    Exit Select 
    Case 2 
    g.DrawEllipse(pen, x0, y0, cx, cy) 
    Exit Select 
    Case 3 
    g.DrawRectangle(pen, x0, y0, cx, cy) 
    Exit Select 
    End Select 
    g.Dispose() 
    pen.Dispose() 
    End If 
    End Sub 
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) 
    Dim cx As Integer = x - x0 
    Dim cy As Integer = y - y0 
    Dim pen As Pen = New Pen(Color.Blue) 
    Select Case DrawMode 
    Case 1 
    gB.DrawLine(pen, x0, y0, x, y) 
    Exit Select 
    Case 2 
    gB.DrawEllipse(pen, x0, y0, cx, cy) 
    Exit Select 
    Case 3 
    gB.DrawRectangle(pen, x0, y0, cx, cy) 
    Exit Select 
    End Select 
    drag = False 
    pen.Dispose() 
    End Sub 
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.PaintEventArgs) 
    Dim gx As Graphics = CreateGraphics() 
    gx.DrawImage(bitmap, 0, 0) 
    gx.Dispose() 
    End Sub 
    Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)button1.ForeColor = Color.Red 
    button2.ForeColor = Color.Black 
    button3.ForeColor = Color.Black 
    DrawMode = 1 
    End Sub 
    Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    button2.ForeColor = Color.Red 
    button1.ForeColor = Color.Black 
    button3.ForeColor = Color.Black 
    DrawMode = 2 
    End Sub 
    Private Sub button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    button3.ForeColor = Color.Red 
    button1.ForeColor = Color.Black 
    button2.ForeColor = Color.Black 
    DrawMode = 3 
    End Sub 
    Private Sub panel1_Paint(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.PaintEventArgs) 
    button1.ForeColor = Color.Red 
    button1.Focus() 
    End Sub



European Visual Studio 2017 Hosting - HostForLIFE.eu :: Drawing rubber-band lines and shapes in VB.NET

clock November 13, 2019 08:29 by author Peter

The lack of XOR Drawing feature in GDI+ was not certainly welcome in the programmer's community.

 

I guess it will be hard to survive with this handicap. In spite of this, I would like to show how we can draw rubber-band lines and shapes in GDI+ with just a few lines of code.

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim size As Size = SystemInformation.PrimaryMonitorMaximizedWindowSize 
    bitmap = New Bitmap(size.Width, size.Height) 
    gB = Graphics.FromImage(bitmap) 
    Dim bckColor As Color = Me.BackColor 
    gB.Clear(bckColor) 
    End Sub 
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) 
    Dim p As Point = New Point(e.X, e.Y) 
    x0 = p.X 
    y0 = p.Y 
    drag = True 
    End Sub 
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) 
    Dim p As Point = New Point(e.X, e.Y) 
    x= p.X 
    y = p.Y 
    Dim cx As Integer = x - x0 
    Dim cy As Integer = y - y0 
    If drag Then 
    Dim gx As Graphics = CreateGraphics() 
    gx.DrawImage(bitmap, 0, 0) 
    gx.Dispose() 
    Dim g As Graphics = CreateGraphics() 
    Dim pen As Pen = New Pen(Color.Blue) 
    Select Case DrawMode 
    Case 1 
    g.DrawLine(pen, x0, y0, x, y) 
    Exit Select 
    Case 2 
    g.DrawEllipse(pen, x0, y0, cx, cy) 
    Exit Select 
    Case 3 
    g.DrawRectangle(pen, x0, y0, cx, cy) 
    Exit Select 
    End Select 
    g.Dispose() 
    pen.Dispose() 
    End If 
    End Sub 
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.MouseEventArgs) 
    Dim cx As Integer = x - x0 
    Dim cy As Integer = y - y0 
    Dim pen As Pen = New Pen(Color.Blue) 
    Select Case DrawMode 
    Case 1 
    gB.DrawLine(pen, x0, y0, x, y) 
    Exit Select 
    Case 2 
    gB.DrawEllipse(pen, x0, y0, cx, cy) 
    Exit Select 
    Case 3 
    gB.DrawRectangle(pen, x0, y0, cx, cy) 
    Exit Select 
    End Select 
    drag = False 
    pen.Dispose() 
    End Sub 
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.PaintEventArgs) 
    Dim gx As Graphics = CreateGraphics() 
    gx.DrawImage(bitmap, 0, 0) 
    gx.Dispose() 
    End Sub 
    Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)button1.ForeColor = Color.Red 
    button2.ForeColor = Color.Black 
    button3.ForeColor = Color.Black 
    DrawMode = 1 
    End Sub 
    Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    button2.ForeColor = Color.Red 
    button1.ForeColor = Color.Black 
    button3.ForeColor = Color.Black 
    DrawMode = 2 
    End Sub 
    Private Sub button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    button3.ForeColor = Color.Red 
    button1.ForeColor = Color.Black 
    button2.ForeColor = Color.Black 
    DrawMode = 3 
    End Sub 
    Private Sub panel1_Paint(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.PaintEventArgs) 
    button1.ForeColor = Color.Red 
    button1.Focus() 
    End Sub

 



European Visual Studio 2017 Hosting - HostForLIFE.eu :: Using C# Regions To Improve Code Readability

clock May 17, 2019 09:44 by author Peter

An instructor I once had made a statement that has echoed in my head for years. When you are a programmer, you have two groups of end users, the people who will actually use the software, AND other programmers who may someday have to modify your code. With that in mind, I have always tried to write my code to be as easily readable to other programmers as possible.

Visual Studio .NET gives us some very handy tools to improve readability in our code. One that I am particularly fond of is the #region directive that allows us to collapse code in a customized manor.

Regions are created in this format,
#region MyRegion

your code here
#EndRegion

Everything that falls within the directives will be collapsible.

The method I've chosen to adapt is to create regions for each different type of element in a class (i.e. constructors, variables, methods, properties, enumerators) so that my code can be easily navigated.

Here is an example,

Doing this will keep your code more organized, which in turn will increase efficiency. And someday down the road when another programmer comes across your source code, they will be very thankful.


European Visual Studio 2017 Hosting - HostForLIFE.eu :: Visual Studio Short Keys And Tips

clock March 22, 2019 11:01 by author Peter

Every developer who uses Visual Studio should know or be familiar with the shortcuts which I am going to share here. I hope it will be helpful to the freshers and even the experienced software developer friends.

Visual Studio Shortcut Keys and Tips

  1. Every developer should learn the difference between the concept of running an application in normal mode and in debug mode. Most of the freshers do not know this concept and run the application using F5 or clicking the RUN button in the menu bar of Visual Studio. But when it comes to the performance of Visual Studio and speed, we should know that F5 is used for running the application in debugging mode and for running the application without debugging, it is Ctrl+F5.

    So, in simple words, if the developer wants to start the application in debugging mode, press F5; otherwise press Ctrl+F5.
  2. To put the breakpoints in the code use F9. For this, we have to put the control at the specific line of code and press F9. Debugging is basically used to check the result or see the values which is coming as per expectation. Now if we run the application the control will come to that specific control and then we can see whether the values are coming as per our expectation or not. If it is the method then we have the concept of step in and step out. We use step in  to get into that specific method and to inspect the values in the method; for this we use F11. Step Out is used to see the output of the method, and the F10 key is used.
  3. As a developer, it is very important to write the code in proper format but most of the developers do not follow it (laughing) as their mind and soul waits to complete the task or module. But after some time of development of the code, they feel that the code should be formatted properly for the sake of better understanding and to troubleshoot (i.e debugging). For that purpose Visual Studio has a formatting concept through which we can format the document. To format the document we can use Ctrl+K,d.
  4. Sometimes, we write code which is not used at present but maybe it will  be needed for some other cases or for some specific attribute afterward for any specific conditions. We can comment the code by using Ctrl+K, C which will comment on the selected code.
  5. To remove a comment for the specific code, we can use Ctrl+K, U in Visual Studio.

Hope these small and useful tips will help you guys. I will provide more shortcuts for developers in the next blog.

 



European Visual Studio 2017 Hosting - HostForLIFE.eu :: How To Organize Classes Using Namespaces?

clock February 13, 2019 10:23 by author Peter

Today, in this article, we shall see what namespace actually does and how to organize the classes using namespaces. We use namespaces to organize classes into a logically related hierarchy. Namespaces function as both an internal system for organizing our application and an external way to avoid name collision between source code and application. Because more than one company may create a class with the same name, such as Employee, when we create code, that may be seen or used by third parties. It’s highly recommended that we shall organize our classes by using a hierarchy of namespaces. By practising this, we can avoid interoperability issues on application.

To create a namespace, we simply type a keyword namespace followed by the name. It is recommended to use Pascal case for namespaces.

It is also recommended that you create at least two-tiered namespaces, which is one that contains two levels of classification, separated by a period.

Let us see sample example of a two-tiered namespace.

namespace Infosys.Sales {  
    //define your classes within the namespace  
    public class customer() {}  
}   

Above two-tiered namespace declaration is identical to writing each namespace in nested format, as shown in the following code. 

 

namespace CompanyName {  
    namespace Sales {  
        public class Customer() {}  
    }  
}   

In both cases, we refer to class by using the following code.

CompanyName.Sales.Customer();   

Note

We should avoid creating a class with the same name as namespace.

Commonly used namespaces in .NET Framework
Microsoft .NET Framework is made of many namespaces, the most important one being System. The System namespace contains classes that most of the applications use to interact with operating system.

For example, the system namespace contains the console class which provides several methods, including WriteLine, which is a command that enables us to write code to an on-screen console.

We can access WriteLine method of console as follows.

System.Console.WriteLine("Prem Kumar Rathrola");   

A few of other namespaces that are provided by .NET Framework through the system namespace are listed below. 

  • System.Windows.Forms
    Provides the classes that are useful for building applications based on windows. 
  • System.IO
    Provides classes for reading and writing data to files

  • System.Data
    Provides classes that are useful for data access

  • System.Web
    Provides classes that are useful for building web forms applications


European Visual Studio 2017 Hosting - HostForLIFE.eu :: Shortcuts For Debugging In Visual Studio

clock November 28, 2018 10:06 by author Peter

Debugging is one of the most important aspect of programming. It is crucial to successful software development, but even many experienced programmers find it challenging. With the help of keyboard shortcuts , it can be made faster. So here is the list of all shortcut keys available in visual studio for debugging.

Debugging Shortcuts in Visual Studio
 

Shortcut

Description

Ctrl-Alt-V, A Displays the Auto window to view the values of variables currently in the scope of the current line of execution within the current procedure
Ctrl-Alt-Break Temporarily stops execution of all processes in a debugging session. Available only in run mode
Ctrl-Alt-B Displays the Breakpoints dialog, where you can add and modify breakpoints
Ctrl-Alt-C Displays the Call Stack window to display a list of all active procedures or stack frames for the current thread of execution. Available only in break mode
Ctrl-Shift-F9 Clears all of the breakpoints in the project
Ctrl-Alt-D Displays the Disassembly window
Ctrl-F9 Enables or disables the breakpoint on the current line of code. The line must already havek a breakpoint for this to work
Ctrl-Alt-E Displays the Exceptions dialog
Ctrl-Alt-I Displays the Immediate window, where you can evaluate expressions and execute individual commands
Ctrl-Alt-V, L Displays the Locals window to view the variables and their values for the currently selected procedure in the stack frame
Ctrl-Alt-M, 1 Displays the Memory 1 window to view memory in the process being debugged. This is particularly useful when you do not have debugging symbols available for the code you are looking at. It is also helpful for looking at large buffers, strings, and other data that does not display clearly in the Watch or Variables window
Ctrl-Alt-M, 2 Displays the Memory 2 window
Ctrl-Alt-M, 3 Displays the Memory 3 window
Ctrl-Alt-M, 4 Displays the Memory 4 window
Ctrl-Alt-U Displays the Modules window, which allows you to view the .dll or .exe files loaded by the program. In multiprocess debugging, you can right-click and select Show Modules for all programs
Ctrl-B Opens the New Breakpoint dialog
Ctrl-Alt-Q Displays the Quick Watch dialog with the current value of the selected expression. Available only in break mode. Use this command to check the current value of a variable, property, or other expression for which you have not defined a watch expression
Ctrl-Alt-G Displays the Registers window, which displays CPU register contents
Ctrl-Shift-F5 Terminates the current debugging session, rebuilds if necessary, and then starts a new debugging session. Available in break and run modes
Ctrl-Alt-N Displays the Running Documents window that displays the set of HTML documents that you are in the process of debugging. Available in break and run modes
Ctrl-F10 Starts or resumes execution of your code and then halts execution when it reaches the selected statement. This starts the debugger if it is not already running
Ctrl-Shift-F10 Sets the execution point to the line of code you choose
Alt-NUM * Highlights the next statement to be executed
F5 If not currently debugging, this runs the startup project or projects and attaches the debugger. If in break mode, this allows execution to continue (i.e., it returns to run mode).
Ctrl-F5 Runs the code without invoking the debugger. For console applications, this also arranges for the console window to stay open with a “Press any key to continue” prompt when the program finishes
F11 Executes code one statement at a time, tracing execution into function calls
Shift-F11 Executes the remaining lines of a function in which the current execution point lies
F10 Executes the next line of code but does not step into any function calls
Shift-F5 Available in break and run modes, this terminates the debugging session
Ctrl-Alt-V, T Displays the This window, which allows you to view the data members of the object associated with the current method
Ctrl-Alt-H Displays the Threads window to view all of the threads for the current process
F9 Sets or removes a breakpoint at the current line
Ctrl-F11 Displays the disassembly information for the current source file. Available only in break mode
Ctrl-Alt-W, 1 Displays the Watch 1 window to view the values of variables or watch expressions
Ctrl-Alt-W, 2 Displays the Watch 2 window
Ctrl-Alt-W, 3 Displays the Watch 3 window
Ctrl-Alt-W, 4 Displays the Watch 4 window
Ctrl-Alt-P Displays the Processes dialog, which allows you to attach or detach the debugger to one or more running processes

 



European Visual Studio 2017 Hosting - HostForLIFE.eu :: Live Unit Testing With Visual Studio 2017

clock November 14, 2018 08:41 by author Peter

Visual Studio 2017 v15.3 or higher versions support Live Unit Testing. This feature executes the already-written test cases automatically as a programmer makes the code changes. Live Unit Testing helps a developer to do the following:

 

  • It executes all the impacted Test Cases as a programmer modifies the code and makes sure changes do not break Unit Test Cases.
  • Through the Visual Studio editor, the programmer sees the code coverage in a realistic view.
  • It also indicates which line is covered or not using Live Unit Testing.
  • Live Unit Testing is supported in  both .NET Framework and .NET Core.

Enabling
Live Unit Testing is only available in Visual Studio 2017 with the Enterprise edition. We can enable the Live Unit Testing by going to the following menus - Test > Live Unit Testing > Start.

After enabling the Live Unit Testing for a project, Live Unit Testing shows options as Start, Pause, Stop and Reset.

Configuration
The default configuration can be changed from the Visual Studio Menu Tool > Options > Live Unit Testing > General. We can configure the Live Unit Testing for the Battery and Memory usages, Testcase Timeout, and Logging Level can be set as needed.

Setup Project Solution

  • Open the Visual Studio 2017.
  • Create one Windows Library Project as “ClassLibrary1” and Change the “Class1.cs” to the “AreaCalculator.cs”.
  • Right click on the solution and add a Unit Test Project as “UnitTestProject1” and change the “UnitTest1.cs” to the “AreaCalculatorTest.cs”
  • Add the Reference of the “ClassLibrary1” project to the “UnitTestProject1”.
  • Add the using statement “using ClassLibrary1;” to the “AreaCalculatorTest.cs” in the using statement section.
  • Build the Solution.

Demo
Open the AreaCalculator.cs and add the code as per the below screenshot.
Open the AreaCalculatorTest.cs and paste the below code. I have not added the Test Method for the triangle’s area calculation and incorrectly calculated the Test Method of the square’s area, just to show some behavior of Live Unit Testing.

Replace the below code in the AreaCalculatorTest.cs file
Now start the Live Unit Testing from the Test menu, then an automatic background process triggers and we see an icon in-line with code. Description of each icon is mentioned here

  • Green Tick Mark represents that this Method is covered for the unit testing.
  • Cross Mark represents that this method is covered for the unit testing, but the test case failed during execution.
  • Blue Negative Mark represent that this method is not covered for the unit testing so a test case needs to be created.

Below screenshots represent each icon of the Live Unit Testing

Icon’s in AreaCalculator.cs


Icon’s in AreaCalculatorTest.cs


So, with the help of Live Unit Testing of Visual Studio, a developer will know about the impact of the changes he is making, and if it's covered for unit testing or not. This is an awesome feature of Visual Studio 2017



European Visual Studio 2017 Hosting - HostForLIFE.eu :: Using the BackgroundWorker component

clock September 20, 2018 11:12 by author Peter

The BackgroundWorker allows you to execute operations that take a long period of time such as database transaction or file downloads, asynchronously on a separate thread and allow the user interface to remain responsive.


Start an Operation in the Background
First, you need to add an instance of the BackgroundWorker component to your application, if you use visual studio, just drag it from the toolbox to your application or you can create it manually as follow:
BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 

To start the operation in the background you have to call the RunWorkerAsync() method of the BackgroundWorker, when you call this method the BackgroundWroker starts the execution of the background operation by raising the DoWork event, the code in the DoWork event handler is executed on a separate thread.
BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 
//start the operation on another thread 
private void btnStart_Click(object sender, EventArgs e) 

    backgroundWorker1.RunWokerAsync(); 

//DoWork event handler is executed on a separate thread 
private void backgroundWorker1_DoWork(object sender, DoWorkeventArgs e) 

    //a long running operation 
    Thread.Sleep(5000); 


You can send a parameter to the background operation using the RunWorkerAsync() method. You can receive this parameter by using the Argument property of the instance of DoWorkEventArgs in the DoWork event handler then you cast it to use it in the background operation.

BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 
//start the operation on another thread 
private void btnStart_Click(object sender, EventArgs e) 

    backgroundWorker1.RunWokerAsync(2000); 

//DoWork event handler is executed on a separate thread 
private void backgroundWorker1_DoWork(object sender, DoWorkeventArgs e) 

    int input = (int)e.Argument; 
    //a long running operation 
    Thread.Sleep(input); 


Reporting progress of a background operation using BackgroundWorker

By using the BackgroundWorker you have the ability to report progress updates of the executing operation. To use this options you must set the WorkerReportsProgress to true.

To start report progress you call ReportProgress() method and use it to pass a parameter that have the value of the percentage of the progress that have been completed. This method raises the BackgroundWorker.ProgressChanged event. In the event handler of the ProgressChanged you can recieve the value of the progress precentage on the main thread using the ProgressPercentage property of the instance of ProgressChangedEventArgs.

BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 
backgroundWorker1.WorkerReportsProgress = true; 
//start the operation on another thread 
private void btnStart_Click(object sender, EventArgs e) 

    backgroundWorker1.RunWokerAsync(); 

//DoWork event handler is executed on a separate thread 
private void backgroundWorker1_DoWork(object sender, DoWorkeventArgs e) 

    //a long running operation 
    for (int i = 1; i < 11; i++) 
    {    
        Thread.Sleep(2000); 
        backgroundWorker1.ReportProgress(i*10); 
    } 

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) 

    progressBar1.value = e.ProgressPercentage; 


Canceling a background operation using BackgroundWorker

With the BackgroundWorker you have the ability to cancel the background operation, to do this you first must set WorkerSupportsCancellation property to true.

The next step is to call the CancelAsync() method by doing so you set the CancellationPending property to true, by polling the CancellationPending property you can determine whether or not to cancel the background operation.

BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 
backgroundWorker1.WorkerSupportsCancellation = true; 
//start the operation on another thread 
private void btnStart_Click(object sender, EventArgs e) 

    backgroundWorker1.RunWokerAsync(); 

//a buttun to cancel the operation 
private void btnCancel_Click(object sender, EventArgs e) 

    backgroundWorker1.CancelAsync(); 

//DoWork event handler is executed on a separate thread 
private void backgroundWorker1_DoWork(object sender, DoWorkeventArgs e) 

    //a long running operation 
    for (int i = 1; i < 11; i++) 
    { 
        Thread.Sleep(2000); 
        backgroundWorker1.ReportProgress(i*10); 
        if(backgroundWorker1.CancellationPending) 
        { 
            e.cancel = true; 
            return; 
        } 
    } 


Alert the user in the completion of the background operation
When the background operation completes, whether because the background operation is completed or canceled, the RunWorkerCompleted event is raised. You can alert the user to the completion by handling the RunWorkerCompleted event.

You can determine if the user canceled the operation by using the Cancelled property of the instance RunWorkerCompletedEventArgs.
BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 
//start the operation on another thread 
private void btnStart_Click(object sender, EventArgs e) 

    backgroundWorker1.RunWokerAsync(); 

//a buttun to cancel the operation 
private void btnCancel_Click(object sender, EventArgs e) 

    backgroundWorker1.CancelAsync(); 
}  
//DoWork event handler is executed on a separate thread 
private void backgroundWorker1_DoWork(object sender, DoWorkeventArgs e) 

    //a long running operation 
    for (int i = 1; i < 11; i++) 
    { 
        Thread.Sleep(2000); 
        backgroundWorker1.ReportProgress(i*10); 
        if (backgroundWorker1.CancellationPending) 
        { 
            e.Cancel = true; 
            return; 
        } 
    } 
}  
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 

    if(e.Cancelled) 
    { 
        MessageBox.Show("Operation Cancelled"); 
    } 
    else 
    { 
        MessageBox.Show("OperationCompleted"); 
    } 


Return a value from the background operation
You can return a value from the background operation that in the DoWork event handler using the Result property of the DoWorkEventArgs instance, and you can receive it in the RunWorkerCompleted event handler using the Result property of the RunWorkerCompletedEventArgs instance.

BackgroundWorker backgroundWorker1 = new BackgroundWorker(); 
//start the operation on another thread 
private void btnStart_Click(object sender, EventArgs e) 

    backgroundWorker1.RunWokerAsync(); 

//DoWork event handler is executed on a separate thread 
private void backgroundWorker1_DoWork(object sender, DoWorkeventArgs e) 

    //a long running operation here 
    Thread.Sleep(2000); 
    //return the value here 
    e.Result = 10; 

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 

    //recieve the return value here 
    int returnValue = (int)e.Result; 



European Visual Studio 2017 Hosting - HostForLIFE.eu :: Visual Studio IntelliCode Preview Available

clock August 24, 2018 11:08 by author Peter

Recently, Microsoft has announced the availability of Preview of Visual Studio IntelliCode in its Build 2018 developer’s conference. This is a new experimental tool for Visual Studio users bringing more of the company’s artificial intelligence smart to software development.

It is a set of AI-assisted capabilities which improves the developer’s productivity with features like contextual, IntelliSense and focused reviews for pull requests.
 
The company states -
“The IntelliCode extension augments productivity features in Visual Studio 2017 with insights based on understanding your code combined with machine learning. The first iteration of this extension enhances your IntelliSense experience by sorting completion items—which are recommended in your code context--to the top of the list.”
 
According to the company, IntelliCode is now applicable only for C# code but in future, it will be upgraded to support more languages.

 



European Visual Studio 2017 Hosting - HostForLIFE.eu :: Customize Visual Studio Code Shortcuts

clock August 10, 2018 11:13 by author Peter

A couple of months ago, I started using Visual Studio Code for my development activities. I found myself very uncomfortable with the keys and shortcuts. I have been using Visual Studio for more than 6 years now. So, I was very comfortable with the keys and shortcuts of that. The difference in shortcuts was creating a challenge for me. Should I remember a different set of shortcuts for VS Code? Should I start using some other editor?

Then, I started to customize the VS Code shortcuts. If you are also facing the same issues, then it's time you should consider customizing the Visual Studio Code shortcuts. It’s not worth spending energy on remembering a new set of shortcuts for a specific editor. Following are some tips,

  1. Open keyboard shortcuts in Visual Studio Code and update the shortcuts as per your need.
    Press ctrl+K, ctrl+s to open the keyboard shortcut window. This looks something like below.
  2. You can see the Edit button on the right side of the row (highlighted one). On click of the Edit button, it will ask you to change the combination you want to execute the command for.

    You can change the combination for your convenience.

  1. You can open keybindings.json file and update as per your need.
    To open the keybindings.json, you need to open the Keyboard shortcuts first by pressing ctrl+k, ctrl+s. You can click on the keybindings.json file.
  2. This will open the default keybindings. This is a JSON file which can be modified to get your desired shortcuts.
  1. You can have your custom JSON file with your shortcut commands.
    When you open default keybindings.json file in the right-hand side window, it opens a keybindings.json file where you can write your custom keys and commands.

Given are a couple of commands I have added in the keybindings.json file to work with the VS Code. Please let me know your feedbacks/ comments. Are there better ways I am not just aware of?



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in