Tuesday, March 06, 2007

I came across an annoying little thing trying to trigger an event that updates the UI...

{"Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on."}


This happens because the UI runs in a specific thread. Now we create another thread and try to access the UI thread which throws the above exception. There is a solution in msdn but imo its not a good one.

Thus we need to marshal the event from one thread to the other thread as shown below.

the source (just create a new form called form1 and drag a label and a button on it):

ThreadComponent.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.ComponentModel;


namespace WindowsApplication3 {
public delegate void ShowSomethingHandler(string message);


public class ThreadedComponent {
private Thread _Thread;

public ThreadedComponent() {
_Thread = new Thread(Poll);
_Thread.Start();

}

private void Poll() {
int i = 0;
ISynchronizeInvoke invoker = ShowSomething.Target as ISynchronizeInvoke;
while(true) {
if(ShowSomething != null) {

//ShowSomething("Message N°:" + (++i));
if(!invoker.InvokeRequired) {
object[] args = {"Message N°:" + (++i)};
invoker.Invoke(ShowSomething, args);
} else {
ShowSomething("Message N°:" + (++i));
}


}
Thread.Sleep(1000);
}
}

public event ShowSomethingHandler ShowSomething;
}
}



Form1.cs

namespace WindowsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e) {
ThreadedComponent c = new ThreadedComponent();
c.ShowSomething += new ShowSomethingHandler(c_ShowSomething);
}

void c_ShowSomething(string message) {
label1.Text = message;
}
}
}

Saturday, February 24, 2007

Finished my MCPD: Enterprise applications cerification last week

Sunday, February 04, 2007

Finally managed to solve a problem that has been bugging me for ages now. When tryinng to use the wizard for databinding to an object the Wizard gave an error :
"An unexpected error has occurred"
"Error Message: Object reference not set to an instance of an object"

The solution can be found here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=380441&SiteId=1&PageID=3
Finished the 70-553 upgrade exam. I am now officially
MCTS: .NET Framework
  • Windows Applications
  • WebApplications

Friday, December 08, 2006

Passed my second CRM exam, Extending Microsoft CRM 3.0 today . I am now a Microsoft Certified Business Management Solutions Professional - Microsoft Dynamics CRM Developer.... ;)

Tuesday, December 05, 2006

Struggling to install virtual server RC2 on Vista :)


Found the solution here : http://blogs.msdn.com/virtual_pc_guy/archive/2006/06/05/618547.aspx

in short:

Install Virtual server like this:
start /w pkgmgr /l:log.etw /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-CGI;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;WAS-WindowsActivationservice;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

If this does not work look at the above link for the manual install you just have to install IIS and see that the 'IIS 6 Management Compatibility' is checked

Then I got this error:
The following error occurred:An error occurred accessing the website application data folder.

This is solved by running Internet Explorer as Administrator (make sure you have windows authentication enabled in "Authentication" In your websites managment console)

Thursday, November 30, 2006

Run across a minor issue while trying to install Visual Studion 2005 on Vista.
When installing he suddenly says he can not copy a certain file. you can retry or cancel. Cancel the installation and rerun the setup.exe with "Elevated Administrator Rights" . This should solve that issue. If this does not work try to install the latest version of Daemon tools because second time i tried the elevated administrator rights did not resolve the issue.

When I tried to run Visual Studio I get a warning. I recommend that you read what it has to say because there are numerous issues that may occur...

Do not forget to install the latest service pack either.

Wednesday, November 29, 2006

Today spent a large part of the day installing VISTA on my laptop
Something I had to look for was how to sync my Qtec s200 with vista. Figured out I had to install "Microsoft Windows Mobile Device Center Beta 3 for Windows Vista"

You can download it here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=C23C8E6A-A72D-4AEF-9663-31CE2FEFBADA&displaylang=en

Works more stable than the RC2 from october that I installed on my desktop a month ago. (until now :p)

Monday, November 13, 2006

Installed windows vista and office 2007 this weekend. Looks great only computer is a lot slower now :/ thnking about reverting back.

Only problem I came across is that I could not install daemon tools to mount iso images. Found a very good (free) alternative: elby Virtual CloneDrive is can be found here : http://www.elby.de/fun/software/index.html

Thursday, October 26, 2006

Playing around with the WPF (Avalon) looks neat!

Made my first databound custom control its pretty easy...
I had been struggling with it for a short while but then turned on some scandicrust and it did wonders ;)

Also extending my framework bit by bit. Starts to look quit nice.