Thursday, 4 June 2009

How to use Windows Forms Controls in a multithreaded application

Windows Form and controls needs to be created on UI thread or a thread which pump messages. Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment-threaded. The STA model implies that a window can be created on any thread, but it cannot switch threads once created, and all function calls to it must occur on its creation thread.

We can use the following code to Invoke the call ( which marshal the call to the UI thread) to open the form from non UI threads.
Delegate Sub ProcessForm(ByVal [text] As String)
Dim delegatetoProcessForm As New ProcessForm(AddressOf ProcessStopaRequest)
Application.OpenForms(0).Invoke(delegatetoProcessForm, New Object() {["text"]})

How to: Make Thread-Safe Calls to Windows Forms Controls
http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx

Issues with building a project with "Register for COM interop" for a 64-bit assembly

Error message "File is not a valid assembly".

Visual Studio internally uses the 32-bit version of the assembly registration tool (Regasm.exe).
To work around the problem, add a post build command to call the 64-bit version of RegAsm.exe using the following steps.
1. In project properties, select “Build Events…” from the Compile page.
2. Add the following post build command line "%Windir%\Microsoft.NET\Framework64\v2.0.50727\regasm" "$(TargetPath)"

How to enable Default Form instances (My.Forms)

Default instances make it possible to refer to an instance of a form without having to explicitly create it first. The compiler utilizes My.Forms to create default instances. By default My.Forms is available only for Windows Forms application.
My.Forms Object
http://msdn.microsoft.com/en-us/library/87y2hdsf.aspx
We can use the _MY compilation constants to change the default behavior. If you would like to enable the Forms Default Instances in a Class Library project, you can set the "_MYFORMS" compilation constant as True. We can use the following steps to implement it.
a) On the Project menu, click Properties.
b) Click the Compile tab.
c) Click Advanced.
d) Modify the value in the Custom Constants box. (Add "_MYFORMS=True")
e) Now we can see that there are no errors for “Me.MdiParent = MDIParent1”
Customizing Which Objects are Available in My
http://msdn.microsoft.com/en-us/library/ms233781.aspx
/define (Visual Basic)
http://msdn.microsoft.com/en-us/library/s477hyxw.aspx
Simplify Common Tasks by Customizing the My Namespace
http://msdn.microsoft.com/en-us/magazine/cc188706.aspx

.Net application is showing the "System.InvalidCastException: Conversion from string "0" to type 'Integer' is not valid.

Implement the following steps
1. Open the Regional and Language Options applet from the Control Panel.
2. Note the Current Format.
3. Change the Current Format to English (Australian)
4. Click Apply.
5. Change the Current Format to the noted format, eg, English (US).
6. Click Apply and then click OK.
Related Knowledge Base Articles
=======================
http://support.microsoft.com/default.aspx?scid=kb;EN-US;942460
http://support.microsoft.com/default.aspx?scid=kb;EN-US;948478

Developing Software in Visual Studio .NET with Non-Administrative Privileges

.<http://msdn.microsoft.com/en-us/library/aa289173.aspx>
<http://download.microsoft.com/download/f/f/8/ff8c8040-d1a7-4402-90df-5d1aaa7d37af/dotNETDevVSGroups.pdf>
ASP.NET Debugging: System Requirements
<http://msdn.microsoft.com/en-us/library/kd3se23d(VS.71).aspx>

How to extract SummaryInformation from msi file

We can use "WindowsInstaller.Installer" object to extract SummaryInformation from an MSI file.
Summary Information Stream Property Set
http://msdn.microsoft.com/en-us/library/aa372045(VS.85).aspx
Database.SummaryInformation Property
http://msdn.microsoft.com/en-us/library/aa368257(VS.85).aspx
Installer.SummaryInformation Property
http://msdn.microsoft.com/en-us/library/aa369486(VS.85).aspx