Похожие чаты

What'S the more proper way of closing C# program in

code?
Cause I'm being taught to use ReadKey() as a way to close it

21 ответов

19 просмотров

Environment.Exit(0);

م ب‍ـ
Environment.Exit(0);

no! don't do that. really bad way to stop a program.

How can you close a program with readkey?

م ب‍ـ
Why?

It's about the same as killing a process. That's not clean exit. Background threads are forcibly killed, finally handlers are not executed. Exit is considered an unsafe call.

Dmrr- Автор вопроса
Liza 丽莎
How can you close a program with readkey?

Basically having empty readkey makes it so program closes with a keypress

Dmrr- Автор вопроса
Wizou
no! don't do that. really bad way to stop a progra...

I tried it, it's worse than readkey as it doesn't wait for input

Liza 丽莎
Does it?

If there’s a return after it

Dmrr- Автор вопроса
Wizou
It's about the same as killing a process. That's n...

🤷‍♂🤷‍♂ In a real program yes. In sandbox, I don't care

Dmrr
Even without return

Could you show sample code

م ب‍ـ
🤷‍♂🤷‍♂ In a real program yes. In sandbox, I don't ...

you were litterally answering the question "What's the more proper way of closing C# program" and now you say "in sandbox I don't care" (about code quality) don't give bad advice to others

Dmrr- Автор вопроса
Liza 丽莎
Could you show sample code

It's just Console.ReadKey(); at the end of main class

Dmrr- Автор вопроса
Liza 丽莎
^

No return tho

Wizou
you were litterally answering the question "What's...

When someone is asking about readKey, it means the program is some starter learning staff

Dmrr
It's just Console.ReadKey(); at the end of main cl...

There are 2 type of console app. One with simple one-time task that end after doing it's job. You shouldn't stop it with readKey or something like that. Let it close. Other type is infinit app that run and do jubs until you close it explicitly. Like web apps. It use a infinit loop or something like that. In this kind, you normally close it with ctrl+c or a method that end all pending taks and exit safely

Dmrr- Автор вопроса

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта