How to solve the problem of access to the file: the program fell out with an unhandled exception.
I made this function:

enter image description here

Inserted a loop until this check returns false:

enter image description here

But now the program goes into an eternal cycle. How to solve these problems?

Closed due to the fact that off-topic party PashaPash ♦ 28 Feb '16 at 10:05 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    1. Issue the code in a normal form so that you can understand something. 2. Write what exactly you need to do with the file, read the data from it, write it down or something else, there should be no access problems - I suspect that you are not closing it after opening, but in any case, the option is to cycle and check access redundant. - wind
  • I'm still trying to make out this mess. I can't work with a local editor. The point is that in that piece of code I create several directories, and in one of them - a text file and immediately try to write one line into it - an access error falls out. - GanjaBoss
  • To format the code in the appropriate form, you only need to select it and click 010101 - wind in the editor,
  • And so, and that way - it’s still molded into one heap - GanjaBoss
  • one
    Remove lines from your function starting with File.Create along with the loop! Leave only File.WriteAllText ... and I think your problems will end. - wind

1 answer 1

A lot of options can be used to create a file and write data to it, but for me the easiest is to use the File class. He has a lot of methods, but for your example this one will do for example. Under the link, there are examples of the use and description of possible "expositions", and a lot of additional information (it is not surprising - it’s all the same). The only thing I want to add is work with threads. By examples from the links it is clear that when creating a stream to read or write a file, the "yuzing" construction is used. I do not know how well you are aware of this possibility of the language, but either use such a construct, or close with your hands the threads you create.

  • I already ran across this page in msdn, but threw it away for unnecessary complexity. But, if they offered it to me here, I will try to figure it out once again, thank you very much. - GanjaBoss
  • Not at all - ask specific questions and they will certainly help you here. - wind
  • I understand my last comment did solve your problems? :) - wind
  • I decided. Meeting with the streams delayed until the next problem with I \ O: 3 - GanjaBoss