I'm developing a windows form application that reads a file line by line[In background worker thread] and populates a datagridview[using BeginInvoke]. While this is being done the UI becomes non responsive(Unable to Cancel/Exit or drag window) but I'm able see datagridview being updated. What i know is that this is due to the fact that messages are being pumped into message queue which have higher priority than user input messages.
Is there a way by which the UI can still remain responsive to User Input?
Since you are using
BeginInvoke, you are doing things on the UI thread. If you read line by line and append each line one at a time, it doesn't really help having a background worker there.You should rather add all at once, or at least in blocks, if there is some requirement to update the view while loading. Usually it's faster to just load and then add the data in one go.