Question

I have a C# class that uses a BackgroundWorker to poll a specific database table for changes. If something changes, it fires an event. Additionally, I have a class Token that has a handler for this event which basically sets the tokens state to "dirty".

Now I asked myself if there can be something better than polling the database every few miliseconds. I thought of making an asynchronous method in my token like

public async Task<bool> IsDirty()
{
    return await Something();
}

But what should I await here? My BackgroundWorker only has its Do_Work and RunWorkerCompleted methods. The BackgroundWorker doesn't need to check all the time, but at least when someone calls/awaits the IsDirty() method.

Was it helpful?

Solution

Yes, there is something definitely better than polling the DB. Using SqlDependency in a Windows Application

You can create a dependency object where SQL Server will notify you that something has changed (a record inserted, updated, deleted).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top