Skip to main content

Posts

Showing posts from January, 2012

Working with BacgroundWorker class c#

Microsoft has provided BackgroundWorker class which make it really easy to create background threads easily. Sometimes we need to implement so functionalities in background threads so that UI will not freeze, that is when this class comes handy. Obviously we can create our own threads and manage there lifecycle ourselves but not everyone is efficient with threads and also sometimes the complexity hits back by consuming lot of time which we really do not have in case of rapid application development. When to use : Downloading a large file and showing progress bar. Uploading some information in background but letting the user to work. Creating a polling application etc. Usage: BackgroundWorker is also present in the toolbox and you can drag it from there or like any other control you can create an object at runtime and use it on the fly. It comes with various events and properties, few of them which are really important are: DoWorkEventHandler (event) Thi

Introduction to Design Patterns

This will  be a series of posts and I will keep updating the posts with new links. Design Patterns In software engineering, a   design pattern   is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Uses of design patterns Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns. In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Analogy Looping

Inter-Process communication (between two desktop applications) using WCF

We will break the problem in small sets as this will answer few commonly asked questions like – Self hosting a WCF, Hosting  WCF in desktop application, Inter- Process communication using WCF. We will use the application we created in last post . Please find below the project structure that we will be using.  We are using a “common” project to define the contract so that contracts can be shared between projects. Contract using System.ServiceModel; namespace Common {     [ ServiceContract ]     public interface ICommunicate     {         [ OperationContract ]         string HandShake( string message);     } } Add reference of “Common” project to the main (windows application project - BackgroundApp). Service Class using Common; namespace BackgroundApp.Service {     public class Communicate : ICommunicate     {         public string HandShake( string message)         {             return "Repl

Create a background / taskbar application in c# .NET

Recently, I was working on integration of two windows applications. First application will launch the second application on login and then they both will communicate using pre-defined set of instructions. There were some complications (I am not going into them) and thus we decided to have a third application which actually will act as mediator. First application will launch the mediator (third application) and it will launch the second application. For this purpose we needed to create a task bar application (which will run in background). How To ·          Create a new windows project and delete the default form (Form1). ·          In Program.cs create a new class and inherit it from Form. ·          Please refer the code below. ·          Now change the Main method. In Application.Run change the startup object from Form1 to ApplicationStartUp.   using System; using System.Drawing; using System.Windows.Forms; using BackgroundApp.Properties; namespace B