S
S
Sergey2021-02-24 22:30:38
C++ / C#
Sergey, 2021-02-24 22:30:38

Can't figure out how async works?

As far as I understand (perhaps I misunderstood, correct me), in C# asynchronous methods must wait until the shared resource is freed, and then continue the task.

There is a method:

using(FileStream source = new FileStream(path, FileMode.Open))
                    {
                        using(FileStream target = new FileStream(newPath, FileMode.OpenOrCreate))
                        {
                            await source.CopyToAsync(target);
                        }
                    }


So, if you open the source file you are looking for in another program, then The process cannot access because it is being used by another process.

This is how it should be, and is it possible to wait?

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-02-24
@Bibort

An asynchronous method is waiting for someone inside the method to say - EVERYTHING is ready. There is no mention of any common resources or anything like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question