I have an application that uses a Timer to do a refresh every 10 seconds. The refresh calls a Refresh method, which uses an object with a pre-established connection to our database to Fetch all necessary rows, and then display them in a DataGridView.
I also have a manual refresh button on the DataGridView that also calls the Refresh method. If I manage to click the manual refresh button at the same time that the Timer ticks, and causes an automatic refresh, I run into an issue where two threads are trying to perform the Fetch at the same time, and get an exception because the pre-established connection is already in use.
Is there a way to force the Timer to run on the UI thread, so that this does not happen?
I have already attempted using Application.StartTask to dispatch a task on the UI thread that would perform the refresh, but this still causes the re-entrant problem. Dispatching the task on the UI thread, from what I am seeing, causes Initialization/Display events to kick off, which also call the same pre-established connection to do an initial fill of the DataGridView.
I also tried saving the current SynchronizationContext during Initialization, and then dispatching the Timer event to the UI SynchronizationContext with the same result as using Application.StartTask.
Thanks & let me know if I did not give enough detail!
Wisej can push the updates to the browser (when in a websocket connection) but the grid has an internal threshold for the number of updated cells/rows that when passed it triggers a data reload to minimize the network traffic. The data reload is processed in parallel to user events.
Also, we have a new experimental option in Wisej to create a server side thread timer using Application.StartTimer(). It starts a server side timer that calls your callback in context. However it’s up to your code to manage the timer: dispose when the session terminates, etc. The sample attached uses a client timer, didn’t turn off websocket but it should work the same way since data read requests are always over http.
Did you use a Wisej.Web.Timer or a thread timer?
If you used a Wisej.Web.Timer, it fires an event on the client which is dispatched to the server as a client event. Exactly like a click. All events coming in from the browser in Wisej are synchronized. There is no UI thread in Wisej. Each request coming from the browser is assigned a thread from the thread pool and there synchronized in the order they come in.
If you used a system timer (thread timer) it’s a different issue.
Let me know.
The data read request is processed in parallel. That’s correct. You can protect (synchronize) the specific function using a lock block. You can lock a session object.
I’ll send you sample code.
BTW, you have a TP account with us and can log issues directly on your github private repository at iceteagroup.