- Execute the page on IE.
- Once you have the page up and can see your ActiveX control, switch to Visual Studio and click on the 'Debug' menu item. Click on 'Attach to Process'.
- On the Attach to Process screen, click on 'Select...' next to the Attach to: label. Select Managed Code and click on 'OK'.
- In the Available Processes section, select 'iexplore.exe' and click on 'Attach'.
- You can now debug the code
Monday 30 November 2009
How to Enable Debugging on an Activex component?
Sunday 29 November 2009
Network Monitoring Tools
Thursday 26 November 2009
Xml Serialization and Deserialization using XSD
- Get an XSD file
- Generate the Classes from XSD using xsd.exe tool
- Create a new instance of the object from the XSD e.g. login object
- Use XmlSerializer class to serialize the object and get the result back; you would just need some Factory methods
- Use the serialized data
- Get the xml as string
- Specify the type e.g. login
- Deserlialize the xml to the type specified using XmlSerializer class
- Use the deserialized object
[TestMethod] [Ignore] public void Should_Generate_Xsd_For_Class() { const string Xsd = @"""C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe"""; // /t:{2} /outputdir:{3} var arguments = string.Format("{0} /t:{1} /outputdir:{2}", @"""C:\Tfs\Project\Trunk\Project\bin\Debug\ProjectName.dll""", "Namespace.ClassName", @"C:\Test"); Process.Start(Xsd, arguments); }
Wednesday 25 November 2009
WinForms - Use Mutex to Ensure Only One Instance
The following code enforces that only one instance of your WinForms application runs at every time:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
// this is true only if the namedMutex created newly in the context of the current application
bool namedMutexCreated = false;
using (Mutex mtex = new Mutex(true, "BeaconClientService", out namedMutexCreated))
{
if (namedMutexCreated)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
// when the form is closed, the mutext is released
mtex.ReleaseMutex();
}
else
{
MessageBox.Show("An instance of Beacon Client Service is already running.", "Service Is Running", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show("An error occured when running the Beacon Client Service, message: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Tuesday 24 November 2009
How to Know When A Person Logs on to Windows?
You want to find out when a Person Logs on and Logs off in Windows so that you take further action against it.
How to Fire and Forget a Method Asyncronously
Tuesday 17 November 2009
All About AOP (Aspect Oriented Programming)
- It decouples the business logic from the system plumbing
- It simplifies long-term maintenance
- AOP
- Aspect
- Cross-cutting Concerns
- Advice
- Pointcut
- Join Points
- AOSD
Saturday 14 November 2009
All About StyleCop
- Add all StyleCop files into your solution
1.1. Create a new folder called “Lib” inside your solution directory
1.2. From %Program Files%\MSBuild\Microsoft\StyleCop Copy all files to your “Lib” directory:
Why would you do that:
The reason you should copy the files into your solution is that:
- You may want to customize the default StyleCop violation rules for your specific solution using Settings.StyleCop file
- Other developers who would like to benefit from StyleCop, won’t need to install StyleCop locally. They can get the latest version from source control such as MSS or TFS
2. Open your project file(e.g. myProject.csproj) and import StyleCop project into it
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<Import Project="$(SolutionDir)\Lib\StyleCop\v4.4\Microsoft.StyleCop.targets" />
...
</Project>
Set Violations as Errors:
- Open your project file in notepad e.g. myProject.csproj
- Add StyleCopTreatErrorsAsWarnings to the Debug PropertyGroup tag:
<PropertyGroup>
Then you will get violations as errors:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
...
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
Customize StyleCop Violation Rules For Your Solution:
- Locate Settings.StyleCop file and double click on it
- Check or uncheck a rule
Thursday 12 November 2009
Application Scalability
- http://technet.microsoft.com/en-us/library/cc770558(WS.10).aspx
- http://technet.microsoft.com/en-us/library/bb742455.aspx
- Software-based such as Windows Network Load Balanacing
- Hard-based
- Can be configured for Sticky IP - for TCP
- Can be configured for Sticky Sessions - for HTTP
- Cluster
- Cluster IP Address
- Cluster Node
- Cluster Node IP Address
- Load Balanced Farm
- DNS Round-Robin Load Balancing
- DNS Lookup
- Load Balancing Cluster
- Hardware Load Balancer
- Network Load Balancing (NLB)
- Web Server Farm
Wednesday 11 November 2009
Create an Intelligent Thread-Safe Queued BackgroundWorker
Problem:
If you run the RunWorkerAsync method of normal BackgroundWorker class when a previous RunWorkerAsync has not yet been completed, then you will get an exception. What this means is that before calling the RunWorkerAsync again, you must be sure that the Completed event of the previous call has been reached.
Solution:
Features of my QueuedBackgroundWorker:
- Run different methods asynchronously and get the result back if you would want to.
- All the works will be queued and will run one by one.
- You can have complex input or output arguments.
- It’s thread-safe
QueuedBackgroundWorker:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
/// <summary>
/// This is thread-safe
/// </summary>
public class QueuedBackgroundWorker
{
#region Constructors
public QueuedBackgroundWorker() { }
#endregion
#region Properties
Queue<object> Queue = new Queue<object>();
object lockingObject1 = new object();
public delegate void WorkerCompletedDelegate<K>(K result, Exception error);
#endregion
#region Methods
/// <summary>
/// doWork is a method with one argument
/// </summary>
/// <typeparam name="T">is the type of the input parameter</typeparam>
/// <typeparam name="K">is the type of the output result</typeparam>
/// <param name="inputArgument"></param>
/// <param name="doWork"></param>
/// <param name="workerCompleted"></param>
public void RunAsync<T,K>(Func<T, K> doWork, T inputArgument, WorkerCompletedDelegate<K> workerCompleted)
{
BackgroundWorker bw = GetBackgroundWorker<T,K>(doWork, workerCompleted);
Queue.Enqueue(new QueueItem(bw, inputArgument));
lock (lockingObject1)
{
if (Queue.Count == 1)
{
((QueueItem)this.Queue.Peek()).RunWorkerAsync();
}
}
}
/// <summary>
/// Use this method if you don't need to handle when the worker is completed
/// </summary>
/// <param name="doWork"></param>
/// <param name="inputArgument"></param>
public void RunAsync<T,K>(Func<T, K> doWork, T inputArgument)
{
RunAsync(doWork, inputArgument, null);
}
private BackgroundWorker GetBackgroundWorker<T, K>(Func<T, K> doWork, WorkerCompletedDelegate<K> workerCompleted)
{
BackgroundWorker bw = new BackgroundWorker();
bw.WorkerReportsProgress = false;
bw.WorkerSupportsCancellation = false;
bw.DoWork += (sender, args) =>
{
if (doWork != null)
{
args.Result = (K)doWork((T)args.Argument);
}
};
bw.RunWorkerCompleted += (sender, args) =>
{
if (workerCompleted != null)
{
workerCompleted((K)args.Result, args.Error);
}
Queue.Dequeue();
lock (lockingObject1)
{
if (Queue.Count > 0)
{
((QueueItem)this.Queue.Peek()).RunWorkerAsync();
}
}
};
return bw;
}
#endregion
}
public class QueueItem
{
#region Constructors
public QueueItem(BackgroundWorker backgroundWorker, object argument)
{
this.BackgroundWorker = backgroundWorker;
this.Argument = argument;
}
#endregion
#region Properties
public object Argument { get; private set; }
public BackgroundWorker BackgroundWorker { get; private set; }
#endregion
#region Methods
public void RunWorkerAsync()
{
this.BackgroundWorker.RunWorkerAsync(this.Argument);
}
#endregion
}
1) How to use it:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var worker = new QueuedBackgroundWorker();
worker.RunAsync<int, int>(Calculate, 2);
worker.RunAsync<MultiplyArgument, int>(Multiply, new MultiplyArgument() { A = 1, B = 2 }, MultiplyCompleted);
}
private int Calculate(int a)
{
return a*2;
}
private int Multiply(MultiplyArgument calculateArgument)
{
return calculateArgument.A * calculateArgument.B;
}
private void MultiplyCompleted(int result, Exception error)
{
Response.Write("worker completed, result: " + result.ToString());
}
}
public class MultiplyArgument
{
public int A { get; set; }
public int B { get; set; }
}
Saturday 7 November 2009
Export To PDF
- PrimoPDF
- PDFCreator
- Microsoft Office Add-in to save PDF
- ABCPDF
- Winnovative
IT Organizational Skills
- Taking good notes from meetings, conference calls, etc
- Setting goals and deadlines
- Having projects done on time.
- Communicate regularly about the progress and strategy improvements
- Reporting to your manager weekly about the progress
- Knowing where everything in the office is located.
- Making good use of time.
- Keeping work area stocked and neat.
- Documenting results
- If you have responsibility of other people as well, you should be maintaining their tasks list and chase them up to do their tasks
- Be aware constantly about what you are saying, to whom and what impact it could have; for instance if you say to your non-technical manager that the Server is down and I am working on it, he might be frightened though you know that it's a 1 minute job to make it work!!!
- Microsoft Project
- Microsoft Excel
- Microsoft Word
Thursday 5 November 2009
C# 4.0 New Features
- Dynamic lookup
- Named and optional parameters
- COM specific interop features
- Variance
- The validation of operations of a dynamic object is made at runtime not compile time. So if you have written an incorrect expression, you will only get the error message at runtime.
- DLR (Dynamic Language Runtime) is a new component which runs on top of CLR (Common Language Runtime) and provides dynamic services to C# 4.0.
- http://blogs.msdn.com/b/csharpfaq/archive/2010/07/27/c-4-0-powerpoint-presentations.aspx
- Difference between "dynamic" and "object": http://blogs.msdn.com/csharpfaq/archive/2010/01/25/what-is-the-difference-between-dynamic-and-object-keywords.aspx