| |

VerySource

 Forgot password?
 Register
Search
View: 1519|Reply: 10

Problems with static variables in c #

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-12 18:00:01
| Show all posts |Read mode
In order to share variables, static type variables are defined, but since asp.net is a typical multi-threaded application, when multiple threads execute this set of code at the same time, an error occurs. How to solve it?
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-4-9 23:15:01
| Show all posts
There are many methods of mutual exclusion of threads, semaphores, locks ...
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-10 08:45:02
| Show all posts
Add thread synchronization code
Reply

Use magic Report

0

Threads

26

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-4-11 06:30:01
| Show all posts
lock
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-14 16:45:01
| Show all posts
If you use lock to solve the problem, when there are too many visitors, there will be a phenomenon that the page cannot be opened by clicking (deadlock). Is there any other way?
Reply

Use magic Report

0

Threads

26

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-5 14:00:01
| Show all posts
The static type of shared variables requires a small amount of processing, and the processing speed is extremely fast every time.If your processing of static type shared variables is very long every time, then it can only be said that it is a mistake in your design and should be reconsidered. or You use Mutex.WaitOne for timeout handling
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-10 23:15:02
| Show all posts
ASP.NET programs generally do not define static variables
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-16 10:15:01
| Show all posts
shygzasaid well
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-18 00:30:01
| Show all posts
Why not use Application for shared variables?
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-21 10:00:02
| Show all posts
shygzasaid it well
agree!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list