From where to start a timer for a database polling?

I'm trying to understand a general flow of WPF application, it's not everything clear for me, so, please, help me to understand the following:

If I want my database polling Timer in a WPF application was started not from a code behind file of my main window, but from another separate class, how I should implement this?

Should this class be somehow connected with a main window code behind class? What processes (apart of user actions) can instantiate this separate class and what (apart of user actions) can call the method which starts a Timer?

In the place of this Timer can be any Method, it is important to understand the general architectural principle of application flow and class objects structure.

-------------Problems Reply------------

WPF applications have by default an App class that is called first. If you don't want to connect your timer to the main window (what is your reason?) you can start your timer in the application's Startup event handler.

public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
// Instantiate your class and start the timer
}
}

and in the App.xaml file:

<Application ... Startup="Application_Startup">...</Application>

In response to your comment:

I'd use a BackgroundWorker to execute the database-polling method in the background. You can then kick that method off with a timer or with a control in the UI, without worrying that you're touching the UI thread inappropriately. If you encapsulate this in a class, you can bind a command to the method that launches it and do away with code-behind entirely.

Category:c# Views:1 Time:2010-02-23

Related post

  • What is unit testing? 2008-08-04

    I saw many questions asking 'how' to unit test in a specific language, but no question asking 'what', 'why', and 'when'. What is it? What does it do for me? Why should I use it? When should I use it (also when not)? What are some common pitfalls and

  • DISCUSSION - Uploading and Storing Mass Images 2008-08-06

    So I'm using an app that stores images heavily in the DB. What's your outlook on this? I'm more of a type to store the location in the filesystem, than store it directly in the DB. What do you think are the pros/cons? --------------Solutions---------

  • storing files to a database or just to the local hard-disk? 2008-08-06

    So I'm using an app that stores images heavily in the DB. What's your outlook on this? I'm more of a type to store the location in the filesystem, than store it directly in the DB. What do you think are the pros/cons? --------------Solutions---------

  • What is the best way to do unit testing for ASP.NET 2.0 web pages? 2008-08-07

    Any suggestions? Using visual studio in C#. Are there any specific tools to use or methods to approach this? Update: Sorry, I should have been a little more specific. I am using ASP.Net 2.0 and was looking more for a tool like jUnit for Java. I took

  • How do I retrieve my MySQL username and password? 2008-08-07

    I lost my MySQL username and password. How do I retrieve it? --------------Solutions------------- Stop the MySQL process. Start the MySQL process with the --skip-grant-tables option. Start the MySQL console client with the -u root option. List all th

  • Best Debugging Tools for JavaScript/xulrunner Development 2008-08-07

    In the past few months I began my first serious JavaScript development, as I began developing XUL applications. I use Notepad++ as my editor, but I was pretty appalled to find (as far as I can tell) that Venkman/Javascript Debugger is the tool for de

  • Drop all tables whose names begin with a certain string 2008-08-07

    I'd like a script to drop all tables whose name begins with a given string. I'm sure this can be done with some dynamic sql and the INFORMATION_SCHEMA tables. If anyone has a script, or can knock one up quickly, please post it. If no-one posts an ans

  • How to know when to send a 304 Not Modified response 2008-08-07

    I'm writing a resource handling method where I control access to various files, and I'd like to be able to make use of the browser's cache. My question is two-fold: Which are the definitive HTTP headers that I need to check in order to know for sure

  • SQL Server 2005 and 2008 on same developer machine? 2008-08-07

    Has anyone tried installing SQL Server 2008 Developer on a machine that already has 2005 Developer installed? I am unsure if I should do this, and I need to keep 2005 on this machine for the foreseeable future in order to test our application easily.

  • Why should I learn Lisp? 2008-08-07

    I really feel that I should learn Lisp and there are plenty of good resources out there to help me do it. I'm not put off by the complicated syntax, but where in "traditional commercial programming" would I find places it would make sense to use it i

  • MOSS SSP Issue - Failed database logons from deleted SSP 2008-08-07

    We've been having some issues with a SharePoint instance in a test environment. Thankfully this is not production ;) The problems started when the disk with the SQL Server databases and search index ran out of space. Following this, the search servic

  • How much database performance overhead when using LINQ? 2008-08-07

    How much database performance overhead is involved with using C# and LINQ compared to custom optimized queries loaded with mostly low-level C, both with a SQL Server 2008 backend? I'm specifically thinking here of a case where you have a fairly data-

  • Is a "Confirm Email" input good practice when user changes email address? 2008-08-07

    My organization has a form to allow users to update their email address with us. It's suggested that we have two input boxes for email: the second as an email confirmation. I always copy/paste my email address when faced with the confirmation. I'm as

  • What point should someone decide to switch Database Systems 2008-08-07

    When developing whether its Web or Desktop at which point should a developer switch from SQLite, MySQL, MS SQL, etc --------------Solutions------------- It depends on what you are doing. You might switch if: You need more scalability or better perfor

  • Should I use the username, or the user's ID to reference authenticated users in ASP.NET 2008-08-07

    So in my simple learning website, I use the built in ASP.NET authentication system. I am adding now a user table to save stuff like his zip, DOB etc'. My question is: In the new table, should the key be the user name (the string) or the user ID which

  • Version control PHP Web Project 2008-08-07

    We have a php project that we would like to version control. Right now there are three of us working on a "Dev" version of the project that all have our Eclipse linked to it with just an external folder, and thus no version control. What is the right

  • What are good regular expressions? 2008-08-07

    I have worked for 5 years mainly in java desktop applications accessing Oracle databases and I have never used regular expressions. Now I enter Stack Overflow and I see a lot of questions about them; I feel like I missed something. For what do you us

  • How should I organize my master ddl script 2008-08-07

    I am currently creating a master ddl for our database. Historically we have used backup/restore to version our database, and not maintained any ddl scripts. The schema is quite large. My current thinking: Break script into parts (possibly in separate

  • .NET Remoting Speed and VPNs 2008-08-07

    I'm working on a project which uses .NET Remoting for communication between the client application and an object server. For development, the client, server, and MSSQL database are all running on my local development machine. When I'm working at the

  • Locking a SQL Server Database with PHP 2008-08-07

    I'm wanting extra security for a particular point in my web app. So I want to lock the database (SQL Server 2005). Any suggestions or is this even necessary with SQL Server? Edit on question: The query is failing silently with no errors messages logg

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.167 (s). 11 q(s)