|
Thanks alot for your description , but suppose there is a memory problem or GC problem , should i reinstall .NET Framework to my machine (WIndows 2000 Server)?
agmb
|
|
|
|
|
Yes, you can try that. I don't really expect it to help, but it will at least elliminate a possible reason for errors.
---
b { font-weight: normal; }
|
|
|
|
|
Hi everyone,
Please help me with this program:
A program to simulate the calculation of 1 + 2 + 3 ...+ 999 +1000.
Use multiple threads to simulate multiple reactions in an array of 1000 elements happening at the same time.
For example, 1 + 2 = 3
4 + 6 = 10
3 + 5 = 8
7 + 9 = 16
8 remaining
and then those numbers continue add each other randomly, the process continues until there is only 1 number left.
Thanks so much
eric
|
|
|
|
|
someone don't want to do their homework on their own ;P;P
|
|
|
|
|
This is the forum so that everyone supposes to discuss together.
This is my assignt actually. I need help.
I try to use Random.Next in multiple arrays and remember the old elements in an separate array.
But I need discussion from anyone who is better than me then.
Thanks
eric
|
|
|
|
|
eric_tran wrote: This is the forum so that everyone supposes to discuss together.
Yes, but school is a place where YOU Learn. If your teacher found you soliciting for answers here i assure you you would be failed.
|
|
|
|
|
Thanks
But this is an open assign, my teacher expects me to do it with any help as long as I understand it.
I didn't let my assignt to someone doing it.
I've been doing it. I just need discussion.
Thanks
eric
|
|
|
|
|
hehe, shurly, but your questions should be more spesific.
First, you need to know how many thread's you have to youse.
Let's asume that you should youse 2 threads.
Use an ArrayList with 1000 records with values from 1 to 1000.
The ArrayList can only be accessed by on thread at a time, so you need a parameter that determen that the
ArrayList is available for accessing.
lets say it is a
bool bIsAccessable = true;
So, the first thread starts, it looks if bIsAccessable is true, if so it sets it to false.
The second thread starts, it looks if bIsAccessable is true, but it isen't so it has to wait,
so now you need a timer, that should hold the thread for some millisecound, and then se if bIsAccessable is true, and so one and so one.
the first thread that know has access to the ArrayList,
gets the length of the ArrayList and creats a 1 random number, with max value of ArrayList.Count (1000)
Get's the rows value, and removes it from the the ArrayList, then
stores the value. Then it should get a new random number, whit max value of ArrayList.Count (that now is 999)
Get's the rows value, and removes the row from the the ArrayList.
Now the first thread can let go of the ArrayList becouse it has it's 2 numbers, so it sets the bIsAccessable to true.
Now the second thread can access the ArrayList, meenwhile the first thread calculates the sum of the 2 values it got.
I think there is a flau in my theory "What if both threads access the bIsAccessable" at the same time?"
So a think you need a thread that takes care of who that can access the ArrayList.
Well this should get you started.
Hope it helps
Thomas
|
|
|
|
|
thomasa wrote: I think there is a flau in my theory "What if both threads access the bIsAccessable" at the same time?"
Yes, there is. The method is fundamentally right, but the flaw is that there is a slight period of time beween checking the value of the flag and setting the flag, where another thread could check the flag and also find it true.
Use the lock keyword to obtain exclusive access to an object:
lock (theList) {<br />
...get values<br />
}<br />
...process values<br />
lock (theList) {<br />
...put the result back<br />
}
---
b { font-weight: normal; }
|
|
|
|
|
Thanks so much Thomas.
This is the advance level of my assignt.
I used 5 threads. My method is similar as yours.
But I've been struggling with the coding.
Hopefuly I can get help later
Eric
eric
|
|
|
|
|
Hi.
I am wondering how one goes about making an application not work after some time. I just made an app and I want it to work for a year and then the buyer needs to buy again. How do I do that? This is similar to how many companies do, they license their software for some time and after some time it stops working or something like that. How is this done?
Thanks,
F
|
|
|
|
|
i don't have professional experience in this matter,
but the first thing that comes up with me , is registering a start date somewhere in registry, and make your application check that date everytime it starts. I would not check the system time, because with putting it back, the program should work again.
Now i'm curious how other people think of this.
|
|
|
|
|
You have to store the date the application was started the first time, then every time the application starts you have to compare todays date with the stored date.
The user can ofcours youst revind the date in his bios, to make the application work again.
Thus, if you the application requirs internett access, you could stor the date on a private server, and compare it with the servers "todays date".
|
|
|
|
|
Hi.
Can you maybe elaborate a little more? Isn´t there some simple way of doing this? I was thinking of DateTime, perhaps creating a thread that checks to see if year is 2007 and then disables something in the program. Do you know how to do this?
Thanks,
F
|
|
|
|
|
Hi.
I was thinking about creating a thread that checks to see if year is 2007 and then disables something in the app. Is this possible? Perhaps someone can show me how this is done as it seems to be an easy way of doing this.
Thanks,
F
|
|
|
|
|
Why don't you check when the executed file was created? Although you can change the created date/time of a file.
Even when the user changes the date/time the created date will always remain the same, then you have the problem of getting the correct date/time for that user because if they set the clock back, DateTime.Now() should return the changed date/time.
If internet access is require then I am sure you can connect to Microsofts time server to get the time, or you could use your own server.
You could try and get the bios time? Not sure how tho, and if the date/time is set back further then the date/time created for that file then stop it from working.
Then you'd have to set some sort of flag, file/registry etc just incase the user uninstalls and reinstalls as the date it was created will now be the day they un/installed the software.
Hope that helps?
Gav
|
|
|
|
|
What you are trying to do is not easy at all (if you want something reliable at least.)
You could start by reading this article[^].
Luis Alonso Ramos
Intelectix
Chihuahua, Mexico Not much here: My CP Blog!
|
|
|
|
|
hi everybody pleas help me how to declare update varible with name @Marks1???
down you can see what i get when i try to exsecute command update?
Server Error in '/PrinterNew' Application.
--------------------------------------------------------------------------------
Must declare the variable '@Marks1'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@Marks1'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Must declare the variable '@Marks1'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +186
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +493
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +915
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1140
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +107
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3836
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
|
|
|
|
|
Hi.
Judging from what I see your problem might be:
a) The name of the variable is not OK.
b) Variables are declared so: type var-name.
Hope this helps.
|
|
|
|
|
I know how to declare varible but i don't know how to declare varible for datagrid this varible shout be for one datadroplist who is in this datagrid.
this is what i have in my asp code??
<asp:cookieparameter cookiename="Marks1" name="@Marks1">
|
|
|
|
|
This error is telling you that Sql Server does not know about the SQL variable '@Marks1'. Are you attempting to call a stored procedure in this code? It sounds like the error is probably in that rather than in your C#...
Regards,
Rob Philpott.
|
|
|
|
|
Hello,
I have the following:
<br />
private void button_Click(object sender, EventArgs e)<br />
{<br />
this.demoThread = new Thread (new ThreadStart (this.ThreadProcSafe));<br />
this.demoThread.Start();<br />
<br />
}<br />
<br />
private void ThreadProcSafe ()<br />
{<br />
MyReference.Form2 form2 = new Form2();<br />
Application.Run(form2);<br />
}<br />
<br />
<br />
<br />
I was just wondering if that's the proper way to do it? It must be a separate thread, but I just don't know if doing it the way I am doing it is good programming practice. Is there information regarding launching applications on a separate threads. Sort of showing top-level windows in it's own process thread.
Thank you.
|
|
|
|
|
You want a new process, not a new thread.
System.Diagnostics.Process.Start(@"C:\MyApp.exe");
|
|
|
|
|
I load the other reference in the form of .dll. So how would I call that as another process? Other thing, my main window, that is launches the other processes, will show all the windows open in the window menu, and the only way to interact with the other windows is by using the worker threads.
Thank you.
|
|
|
|
|
Read up on .Net app domains. What are you trying to do? Do you have to have a separate application or process running? Ok, only having one running app makes life easier so that you can use object references and all that. The app is already running, just show some forms without using threads. The UI is the UI. It should be thin. You don't have to model the UI after the physical implementation details (threads). Use the minimal amount of threads to do some work so that the UI isn't hung up waiting for a calcuation to finish (the UI remains snappy). When the thread is done, update the form UI to present it to the user. A form should not have much code in it, it is just the presentation to the user. Lookup BeginInvoke() on CP and google.
If you really want to have some fun, you could use .Net Remoting to talk between apps. This way you can have independent apps up and they can talk to each other. Usually this is done when you have the exes running on separate machines.
Jim
|
|
|
|
|