pick a number from 1 to 10

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,

i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?

thanks,
rodchar
 
hi Rodchar,

i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10.
You may use ten links or buttons. But what should happens after they
"picked" a number?
how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
Why do you want to do that?


mfG
--> stefan <--
 
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Why do you want to do that?
I want to make it a game.
 
rodchar said:
I just want to make sure the first 10 users that select a number and that
each user has a unique number

Then yes, you will have to have _some_ mechanism to ensure that each
user cannot pick the same number some other user does.

But since you are trying to implement this in an ASP.NET project, you
need to post your question in the ASP.NET newsgroup. Your concurrency
issues are specific to ASP.NET and thus you will only get the best
answer to your question posting it there.

Pete
 
thanks all for the help,
rod.

Peter Duniho said:
Then yes, you will have to have _some_ mechanism to ensure that each
user cannot pick the same number some other user does.

But since you are trying to implement this in an ASP.NET project, you
need to post your question in the ASP.NET newsgroup. Your concurrency
issues are specific to ASP.NET and thus you will only get the best
answer to your question posting it there.

Pete
.
 
hey all,

i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time).. Is
this a concurrency issue?

thanks,
rodchar

FIFO. That's not a concurrency problem. First number picked gets
withdrawn from the pool.

You stupid or what?

Thanks for posting here. Back to skool for u.

RL
 
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?

If it would be a problem having two users pick the same number, then
you will have a concurrency problem.

The two standard mechanisms for this is:
1) a user that comes in locks all the numbers and other users
must wait until the first user has made a pick and then
that number is not available any more
2) you allow users to pick numbers in parallel, but users that
pick a number already picked will get an error telling them
that someone else just took that number and they have to
pick another

You can do it either in memory using standard synchronization
(lock keyword in C#) or using a database with good transaction
support. The last option supports clustering.

Arne
 
Use the singelton pattern to create this kind of manager and ensure that
your application runs only in one AppDomain on the IIS.

And cross fingers that the load will never be so big that clustering
is needed.

Arne
 
Then yes, you will have to have _some_ mechanism to ensure that each
user cannot pick the same number some other user does.

But since you are trying to implement this in an ASP.NET project, you
need to post your question in the ASP.NET newsgroup. Your concurrency
issues are specific to ASP.NET and thus you will only get the best
answer to your question posting it there.

The concurrency issues are not ASP.NET specific.

They are the same whether it is browser--(HTML/HTTP)--web app,
fat client--(SOAP/HTTP)-- web service,
fat client--(binary/socket)--server or something else.

Arne
 
Arne said:
The concurrency issues are not ASP.NET specific.

Sure they are. The mere fact that it's an ASP.NET application
guarantees that.

In a C# program, the solution is trivial. But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.

If nothing else, the fact there's no way for someone unfamiliar with
ASP.NET to know for sure that every client is being serviced by the same
process makes the question ASP.NET-specific, even if the answer turns
out to be the same.

Pete
 
Arne said:
And cross fingers that the load will never be so big that clustering
is needed.

Would clustering result in multiple processes being handled by multiple
processes? If so, I _really_ am boggled by your assertion that the
concurrency issues are not ASP.NET-specific.
 
hi Arne,

And cross fingers that the load will never be so big that clustering
is needed.
Indeed, but then, picking one number from only ten makes no sense at all ;)


mfG
--> stefan <--
 
Peter said:
Would clustering result in multiple processes being handled by multiple
processes? If so, I _really_ am boggled by your assertion that the
concurrency issues are not ASP.NET-specific.

"multiple processes being handled by multiple process" should, of
course, read "multiple clients being handled by multiple processes"
 
Peter Duniho said:
Sure they are. The mere fact that it's an ASP.NET application
guarantees that.

In a C# program, the solution is trivial. But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.

Really? How do you prevent two users from logging on to a server and
running the same application and picking the same number at the same
time?

Or if the application is deployed to a share, how do you prevent two
users from two different machines running the same application and...
 
J.B. Moreno said:
Really? How do you prevent two users from logging on to a server and
running the same application and picking the same number at the same
time?

I don't understand your question. The "how do you..." question is
exactly my point. AFAIK, nothing in ASP.NET _does_ guarantee that.
Surely there are specific ways using ASP.NET to provide for that
guarantee (such as using a database as Arne suggested, or having a
special-purpose server process shared among all clients), but those ways
will necessarily be specific to ASP.NET.

Frankly, your question simply reinforces my point: if one knows in
advance one is dealing with a single process, the question is simple to
answer. But with ASP.NET in the picture, it gets a bit different, and
in a way that is specific to ASP.NET.
Or if the application is deployed to a share, how do you prevent two
users from two different machines running the same application and...

What's that got to do with ASP.NET, or the original question for that
matter?
 
Peter Duniho said:
I don't understand your question. The "how do you..." question is
exactly my point. AFAIK, nothing in ASP.NET _does_ guarantee that.

And nothing would guarantee it if it was a WinForm application deployed
to a Windows 2008 server.

Which is the point, the issue isn't windows versus ASP, but
multi-process versus single. The problem isn't ASP specific, and the
solution is unlikely to be ASP specific.
Surely there are specific ways using ASP.NET to provide for that
guarantee (such as using a database as Arne suggested, or having a
special-purpose server process shared among all clients), but those ways
will necessarily be specific to ASP.NET.

Using a database isn't ASP.NET specific. Neither is having a separate
process to act as a middle man.
Frankly, your question simply reinforces my point: if one knows in
advance one is dealing with a single process, the question is simple to
answer. But with ASP.NET in the picture, it gets a bit different, and
in a way that is specific to ASP.NET.

C# and no ASP.NET does not exclude multiple processes.
What's that got to do with ASP.NET, or the original question for that
matter?

It shows that the problem is multiple processes running at the same
time, not whether it's a ASP.NET process or console application.

The solution is to create a choke point of some kind, and again that
isn't necessarily ASP specific.

While this isn't a syntax problem, neither the problem nor the solution
require ASP.NET.
 
J.B. Moreno said:
And nothing would guarantee it if it was a WinForm application deployed
to a Windows 2008 server. [...]

That depends on the deployment. But if the deployment is specifically
some sort of server context where something outside the C# program is
somehow creating the potential for multiple processes, then the answer
to that question is STILL outside the scope of this newsgroup.

Because the OP is using ASP.NET, I suggested the ASP.NET newsgroup.
That is a newsgroup where server issues are very much on-topic while
still being specifically connected to the actual API the OP is using,
and the OP will find much greater expertise than here.

You may want to argue that the OP would be even better served by a forum
that is even more specifically about deploying server-side
implementations than the ASP.NET newsgroup. That seems like a fine
point, and it might be true. But there's no justification at all for
suggesting that the topic has anything to do with C# specifically, and
even suggesting it's a normal .NET topic is a stretch.

Pete
 
While this isn't a syntax problem, neither the problem nor the solution
require ASP.NET.


OK you got me--that's true. You cannot guarantee, unless you use
GUIDs, that two users will not pick the same two numbers. But one
simple solution is indeed to use GUIDs. Assign each number to a GUID,
first come, last served. This is simply an UPDATE problem in SQL.
You can have "LAST IN WINS" (the default) in the case two users are
online at the same time and pick the same number.

But, if you don't want the default (LAST IN WINS) be aware it's a lot
of work. I got tangled up in it myself and could not make it work.
So I switched to LAST IN WINS for the odd case where two users are
online at the same time and pick the same number. As a practical
matter that's rare anyway, unless you have 1000s of users online at
the same time. But I digress.

RL
 
Back
Top