Archive for the ‘Windows Forms’ Category

Windows 10 – KB3147458 – Windows update failure – 0x80070003 – ERROR_PATH_NOT_FOUND – FIXED!!

April 26th, 2016 2 comments

The Problem

I have numerous windows 10 machines and my desktop PC has started failing to apply the windows updates.

These two windows updates failed to install

  • Cumulative Update for Windows 10 Version 1511 for x64-based Systems (KB3140743)
  • Cumulative Update for Windows 10 Version 1511 for x64-based Systems (KB3147458)

Note: because of these issues I have set my windows update to notify and let me choose when to download and install

Setup Windows Update via Group Policy

The Symptoms

  • You are told there is a new update and you let it download and install.
  • Once completed you are asked if you wish to restart, so click restart
  • You are told that it is getting ready to install updates
  • In my case it gets to 3% and then reboots
  • Next it gives a message, “Cannot complete install. Undoing changes”
  • The computer reboots again
  • On login, you are told some udpates were unsuccessful

The Issue

In my particular instance this fixed the issue.

I first went and viewed the log file: C:\Windows\Logs\CBS\CBS.log
Depending on how long it has been since the error occured you may need to look for a file called “CbsPersist_20160425131704.log” where the number is the date/time of when the log file was created.

Open the file and search for “0x80070003 – ERROR_PATH_NOT_FOUND”

I found mine is a section as follows:

The issue is that one or more of the 16 drivers it is attempting to update has failed to be installed with a Path Not found error, but which one/s?

To find the details of the erroring driver update go to this file: c:\windows\Inf\

Open this file and search for “Exit status: FAILURE”

I found the following, item of interest:

As you can see it is saying path not found in the FileRepository folder.
So I went looking and its right, I had no “capimg.inf_amd64_5a4379f63bea786c” folder!

The fix

In my case I have many other healthy windows 10 machines so I went and looked and sure enough they had the missing folder.

So I firstly copied the folder onto a usb key from the healthy machine.

There is a security issue with the FileRepository folder in that you will have no permissions on this folder.
To copy the “capimg.inf_amd64_5a4379f63bea786c” folder into the FileRepository directory you will need to go into the Advanced security and take ownership first. I am an admin on my PC, so I changed ownership to the Administrators group and then gave administrators full persmissions.

Once that is done you should be able to copy the missing folder into the FileRepository directory.

Next try to apply the update again and in my case it worked.

Windows10Update Success

VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)

Categories: Uncategorized, Windows Forms Tags:

Background Worker Thread Code Sample with event handlers and cross thread invoke

March 30th, 2012 3 comments

The Problem

So you want to create a windows form application. It needs to do the following:

  1. Do some work where its processing multiple items
  2. Have a progress bar that updates the progress of the application as it runs.

Seems easy.. well here are the complexities:

  1. You want the main process to run on a background thread, so that the UI thread is available to update and render
  2. The background thread will need to raise events back to the main application to notify the application of the background thread progress.
  3. The progress bar will need to be updated to reflect the progress.
  4. The call to update the UI will crash because it is actually doing a cross-thread call, (the background thread, is trying to update the UI thread and this will crash.

This will walk you through the pattern for implementing this solution.

Background Worker Thread

This as the name suggests is a thread of execution that runs in the background in the application leaving the UI thread to do what it is good at, UI rendering.

If you were to try and have a method that processed 1000 records @ 2 seconds per record, and tried to update the progress bar on processing each record the UI would not render the progress bar as the UI thread is caught up in the process of doing the work.
Doing the work on the background thread leave the UI thread to update the UI whilst the background thread gets on with doing the work.

What is the background thread and how do I create one?

First of all lets create a visual studio solution. I am going to create an empty windows form application called WorkerUtility. I will place the following controls on it.

  1. A button btnGo – labeled Go
  2. A progress bar; and
  3. A label called lblProgress – to show the % complete

The background worker thread can be found in the toolbox under the “Components” section.
Drag the background worker thread onto you form and you will end up with a control called backGroundWorker1.

It should look like this:

Set the following properties on the background worker control

  • WorkerReportsProgress true

Double click on the “Go” Button and setup the following Code

private void btnGo_Click(object sender, EventArgs e)

Performing the Work and Raising Events

I am going to simulate processing a 126 items @ Random number of seconds between 0 and 2 seconds, by looping and pausing the background thread. You could be doing anything in the processing block, for example, read data from the database loop through the rows and perform file system tasks based upon the data?

I will be performing work but each time an item is processed I want to tell the UI thread so that it can update the progress bar. To do this I will need to use events and I am going to create some custom event args.

Create a class called ProgressUpdatedEventArgs like the following:

using System;

namespace WorkerUtility
    public class ProgressUpdatedEventArgs : EventArgs
        public ProgressUpdatedEventArgs(int total, int progress)
            this.Total = total;
            this.Processed = progress;

        public int Processed { get; private set; }

        public int Total { get; private set; }

I will encapsulate the logic in a class called Processor.cs. Create a class as follows:
This will house the event handler and raise events back to the UI thread

The main point of Interest in the following code is the creation of the event handler on the page with a delegate method declaration and an event handler. The RaiseEvent method is called on each file that is processed.

using System;

namespace WorkerUtility
    public static class Processor
        public delegate void ProgressUpdatedEvent(ProgressUpdatedEventArgs progressUpdated);

        public static event ProgressUpdatedEvent ProgressUpdated;

        /// <summary>
        /// Main execution method that does the work
        /// </summary>
        public static void Execute()
            int total = 126 // this creates funny percentages
            Random randomGenerator = new Random();
            for (int i = 0; i < total; i++)
                // Do some processing here

                double delay = (double)randomGenerator.Next(2) + randomGenerator.NextDouble();

                int sleep = (int)delay * 1000;


                RaiseEvent(total, i + 1);

        private static void RaiseEvent(int total, int current)
            if (ProgressUpdated != null)
                ProgressUpdatedEventArgs args = new ProgressUpdatedEventArgs(total, current);

Cross-Thread method invoke, handling the callback

Now we need to set up an event handler in the main form so we can update the UI when the event is raised.

On the Background Worker Switch to the “Events” properties and double-click on “DoWork” to create the “DoWork” event handler.

Go to the _DoWork event handler and change as follows:

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    Processor.ProgressUpdated += new Processor.ProgressUpdatedEvent(Processor_ProgressUpdated);

void Processor_ProgressUpdated(ProgressUpdatedEventArgs progressUpdated)


So this is where the tricky bit comes in. We need to implement the _ProgressUpdated callback.
If we were to go directly to update the UI, we would get a cross thread exception and the program would crash.

Cross-thread operation not valid

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

If you check the InvokeRequired method it will return true in this scenario so we need to perform a cross thread call to get from the background worker thread, that the “ProgressUpdated” event is raised on, to the UI thread to make the changes in the UI.

This is done as follows, firstly you need a delegate for the method invoke method callback and an Update Method to handle performing the UI Update.

public delegate void ProgressUpdatedCallaback(ProgressUpdatedEventArgs progress);

private void Processor_ProgressUpdated(ProgressUpdatedEventArgs progressUpdated)
	if (InvokeRequired)
		Invoke(new ProgressUpdatedCallaback(this.UpdateProgress), new object[] { progressUpdated });

private void UpdateProgress(ProgressUpdatedEventArgs args)
	if (progressBar1.Maximum != args.Total)
		// initial setup
		progressBar1.Minimum = 0;
		progressBar1.Maximum = args.Total;
		progressBar1.Style = ProgressBarStyle.Continuous;

	progressBar1.Value = args.Processed;

	if (args.Total > 0)
		double progress = args.Processed / (args.Total * 1.0);
		lblProgress.Text = progress.ToString("P2");



Here is what it looks like running

Here is the full working code sample in a VS2010 solution.

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)

Categories: c#, Windows Forms Tags:

Setup App.Config during .msi install, msi re-installing

August 17th, 2011 No comments

The Issue

I wrote a windows form application that deployed  via an .msi installer.

The application has an App.Config file which contains a single configuration value. I wanted to prompt the user for this value during the installation wizard and write it to the application.exe.config file as part of the installation process.

I used the built in Setup project in Visual Studio 2010.

The solution

I could write it all here in my post but I have found one that was created earlier:

I essentially implemented the same solution but I wrote my .config file using a StringBuilder and deleted and re-wrote the.config file in the Post install custom action.

The other thing is that I created short cuts to the application by right-clicking on the primary output and chosing “Create Shortcut”, then I copied this to the desktop and users program menu locations.

The problem

I was installing this for “Everyone” and it would work fine for me, but when other people logged in and tried to launch the program the .msi would run and the application.exe.config file was being overwritten with the orginal version that was deployed with the .msi, which does not contain the users input.

The Fix

The problem is complicated and is related to the application short-cut.

It appears that by default the short-cuts created in the msi are “Advertised ShortCuts”.

According to microsoft when an advertised shortcut is activated “.. the installer verifies that all the components in the feature are installed before launching this file”.

This means that if you delete any of the files that were deployed to the installation location then the .msi will attempt to fix them and re-install the missing components, which in my case means that the application.exe.config is overwritten.

You can identify the “Advertised” short cut by looking at the “Properties” of a short-cut and the “Target” will be greyed out.

I found the post below that identifies an easy way to disable advertised shortcuts.

You need to set the “DISABLEADVTSHORTCUTS” property on the .msi. This can be done easily in the installer, by switching to the “user interface editor” and adding a custom textbox page to the UI. This does mean that you will have an empty step in your installation however, so think of some nice use for it like a warning message about this being a free product??

I acutally have my custom UI that is getting details from the user for the “Edit1Property” so in the Edit2Property I set these values and keep it invisible, (otherwise you would set it in Edit1Property)

  • Edit2Value: 1
  • Edit2Visible: false

This updates the property table in the .msi and now all your short-cuts will be normal standard shortcuts.

Cheers ­čÖé

Final Tip: Setting the shortcut icon

Another tip is to set the icon based on the icon embeded in your .exe.

  • In the File System Editor, click on the ShortCut and view the properties
  • Click on the icon property
  • choose browse,
  • change from .ico to .exe
  • browse to the “Primary-Output for…” and choose OK.

It will show you the icons embeded in your .exe and this way you don’t need to deploy a seperate .ico file.

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)

Categories: c#, Windows Forms Tags:

Windows form Label Control Autosize and wrap text vertically

October 27th, 2009 No comments

The other day I was trying to get a label control to autosize vertically and struggled to do it… but there is a simple trick…

Set the maximum width.

If you say “AutoSize=true” but set no MaximumSize.Width property it will just disappear off the right hand side of you form.

Set the MaximumSize.Width and the control autosizes correctly and wraps the text in the label control.



VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)

Categories: Windows Forms Tags:

XP – MouseMove Event fired repeatedly by File Search Animation

June 4th, 2009 No comments

This is a bug with windows XP, caused by the dog animation, that appears by default when you perform a file search.

I had a standard Windows Form Application with a ListView control on it. I setup a MouseMove event on the control.

The normal way this operates is as you move the mouse over the control the MouseMove event fires. Stop moving the mouse and the event does not fire. Seems simple.

Today however I noticed that the MouseMove event was firing repeatedly, even when the mouse was not moving!!

I wrote a very simple windows form test app with only this code and put debug logging on the MouseMove event and found that it was not happening on some other machines.

On the machine where things were going pear shaped I started closing applications until the only things open were some folders that I had been using, and the test app. It was still doing it. I closed all the folders and the MouseMove event stopped firing.

I tracked it down to the following:

  1. Open an file explorer window –> no problem
  2. Press Ctrl + F (find) (the dog annimation apears) –> problem the MouseMove event fires repeatedly even when the mouse is stationary over the control with the MouseMove event
  3. Go “Change Preferences”, and choose “Without an animated screen character”, the dog buggers off and –> No problem.

The animation must be taking control of the mouse and when it gives it back to my form it causes the mouse move event to fire.

Thats 1.5 hours of my life I will never get back.

Thanks Microsoft ­čśŤ

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Categories: Windows Forms Tags: