Our Blogs
English
Español
Skip Navigation Links
News
Our Team
Mentoring
Ken Spencer
Go to home page
Go Search

 
Categories
There are no items in this list.
Other Blogs
There are no items in this list.

Our Blogs > English > Ken Spencer
Background Worker Process

Ah, the sky is falling. Spencer is writing on c#. Guess we all must make a living.

I have a winform app that i wrote for a client. It uses the background worker process to do its magic.

So far, so good. I wanted to put in a hold process in a loop so the loop would hold till the current background process finished. I tried putting a do nothing loop like so:

  while (HoldExecute)
  {
      System.Threading.Thread.Sleep(1000);
  }

but the background thread never ran. Then i had a brainstorm. Good old doevents. Changed this to the following and voila it works:

  Application.DoEvents();
  while (HoldExecute)
  {
      Application.DoEvents();
      System.Threading.Thread.Sleep(1000);
  }

now the app runs the outer loop (not shown) and when the background worker finsihes it sets the HoldExecute variable to false and the inner loop terminates.

This should work in vb too.

Auto Generation of WPF Forms from SQL Server databases
One of the things thats painful in development is just dragging fields over to a form and dropping them. For one form, big deal. But starting  new project and creating 100s of forms is not fun. Billy Hollis showed me some code he wrote to generate a wpf form from a table.
So, i bit the bullet yesterday and wrote a wpf code generator. You simply enter a connection string then click Go and seconds later you have your xaml files.
Of course, the tool needs lots of work. I may update it for a sql magazine article soon.
Heres how it works:
Configuration folder: Create a config folder c:\WPFTemplates. This contains one xaml file with the following code:
<Window x:Class="$$$Window"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid >
$$Rows$$
    </Grid>
</Window>
The $$$Window placeholder is replaced by the tool with a valid .NET name based on the table name.
The $$Rows$$ placeholder is replaced with the form fields generated by the tool.
 
The xaml files are written to the folder: C:\Temp\WPFForms
The tool uses the MetaDataSQLServerSimple class to extract data from SQL Server.
 
You can download the tool source code from here: http://blogs.solidq.com/EN/DevCave/Files/SpencersWPFGenerator.zip
 
Enjoy and send me any changes if you would and i will repost this.
 
Also, check out my other code generator at http://blogs.solidq.com/EN/DevCave/Lists/Posts/AllPosts.aspx . One thing i would like to do is automatically wire up databinding for the generated tools. The other tool at this link does this for one form, so it would not be too hard to accomplish.
 
Just a matter of time...
 
 

 ‭(Hidden)‬ Admin Links