Maxaon3000
Maxaon3000

Reputation: 1129

How do I open a file without blocking in windows?

I see the CreateFile function takes in a FILE_FLAG_OVERLAPPED parameter to make the file io non blocking. However, how can I make the CreateFile call itself non-blocking?

Upvotes: 4

Views: 1558

Answers (1)

doug65536
doug65536

Reputation: 6781

Unfortunately, CreateFile is synchronous. If you need it to be non-blocking, you are probably trying to do I/O in the UI thread. Avoid that.

You did not mention the programming language, so I will assume it is C++. You can use the standard library's threading facilities to offload the I/O intensive work into a worker thread. For example, you could wrap it in a packaged_task or async.

Upvotes: 3

Related Questions