|
OK, let theList be the persistent copy (the one containing data that my app uses). is syncList an identical copy of theList, or just another reference to theList?
in my program, the threads will either read from or write to theList. Read & write operations will be mutually exclusive i.e. they cannot happen at the same time. when theList is being modified all reader threads must wait till the write is complete b4 they can read. Similar, the thread that modifies theList must wait till there's no read ops b4 changing theList.
There's multiple readers, but only 1 writer thread.
How can i apply the Sychronized(), lock(), and SyncRoot in my context?
I am quite new to C#, so I may not know certain things that u assumed that I should know. Can any1 provide me with a more detailed example, or perhaps point me to a more elaborative resource? thanks a bunch.
|
|
|
|
|
viperxp wrote:
is syncList an identical copy of theList, or just another reference to theList?
It is wrapper around theList, which internally contains a reference to it.
viperxp wrote:
How can i apply the Sychronized(), lock(), and SyncRoot in my context?
With Synchronized() you don't have to do anything but ensure that you do all of your reading and writing with syncList.
From the documentation on the "lock statement" (since I couldn't think of the correct wording, but slightly modified):The lock keyword marks a block [of code] as a critical section by obtaining the mutual-exclusion lock for a given object, executing [the code], and then releasing the lock. You use it by passing in a reference to an object which will serve as the 'key' to entering into the lock.
In this case, the 'key' to the ArrayList is returned by the SyncRoot property.
HTH,
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
First of all,
Thanks for prompt reply.
James T. Johnson wrote:
With Synchronized() you don't have to do anything but ensure that you do all of your reading and writing with syncList.
Are u saying that whenever I need to access (be it read / write) theList, I just get the enclose the code block in a lock(syncList.SyncRoot), no matter where the read / write operation lies... in my case, they are in different classes.
From what u wrote, it seems that i dont have to do any checks, i.e. is there any other threads accessing tthe list or not etc b4 commencing my "I/O" operations... is my interpretation correct?
can i put it in this way....
syncList.SyncRoot provides a "safe" reference to theList. whenever any code within lock(syncList.SyncRoot) is running, all other code accessing theList - most probably thru the syncList.SyncRoot reference, regardless of whether it's in a lock() block or not, will have to wait till the "active" lock() block completes?
how about deadlock and "starvation" problems...? e.g. when a thread terminated prematurely, will the lock be released? if not, wut can i do prevent this prob?
Thanks again, yur replies helps a great deal
|
|
|
|
|
By default all forms are inherited from System.Windows.Forms.Form. The wizard generates code like this:
public class Form1 : System.Windows.Forms.Form
That is nice, but I would like to interject a class with common behaviors for all my forms. Like this;
class BaseForms : System.Windows.Forms.Form
and then inherit from there like so;
public class Form1 : System.Windows.Forms.Form
The problem is I get the message below and I am not sure why.
C:\NET_Phil\FormsInherit\Form1.cs(21): Inconsistent accessibility: base class 'FormsInherit.BaseForms' is less accessible than class 'FormsInherit.Form1'
All the wizard generated source is below. I have only modified the lines discussed.
Thanks for your time.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace FormsInherit
{
class BaseForms : System.Windows.Forms.Form
{
public BaseForms()
{
Console.WriteLine("BaseForms");
}
public int iValueAll;
}
///
/// Summary description for Form1.
///
public class Form1 : BaseForms
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
|
|
|
|
|
Make BaseForm public
<a TITLE="See my user info" href=http:
|
|
|
|
|
Yes, I feel dumb, but thank you.
|
|
|
|
|
I don't have much experience with web services beyond basicly reviewing the technology and trying a few demos. I am thinking of using a set of web services in my issue tracking project but I am a little concerned with performance. It is very important to me for the final product to be very responsive, so I don't want to use anything that compromises that.
Assuming the web service were running on a server (Win2k, 1gb, scsi, SQL local) in the same office as the user, exposed through a Windows service, basically just "Get a record", "Save a record", could I expect sub-second response times for total round trips (ie. App requests record to Record received.) I still need some of that second to deal with processing the request by the user and displaying the results.
I know nobody can promise performance, I will eventually have to test it, but I would like to hear from pepole more familiar with me to get a better understanding of what to expect.
One last question, what are the best resources for learning the best way to program web services?
Thanks in advance.
Matt Gullett
|
|
|
|
|
Have you considered using .net remoting, since your application seem to run in a intranet environment. I believe remoting gives better performance than webservices, as it can use binary formatters.
Cheers,
Kannan
|
|
|
|
|
Thanks for the feedback, but no I have not seriously considered .net remoting for several reasons.
1) Not all parts of this application will be written in .NET (I think?)
2) I would like this system to be useable outside the intranet also (if reasonably possible)
3) .NET remoting may be problematic due to the dynamic nature of the structure of issues (See my article series 'The life of a project..." for a better understanding.
4) I want to produce a system that can self-document the changing nature of itself which I don't see how remoting can do.
Anyway, thanks, it's not a bad idea, but I just don't see how I could use it for this project. If you think I could still use it, please let me know.
Thanks,
Matt Gullett
|
|
|
|
|
Sorry Matt, I didn't know you had a article series behind your question
These things happen when you start visiting the lounge and the forums directly without checking out cp main page
I'm reading the first one, thank you for a great looking article
Regards,
Kannan
|
|
|
|
|
It really depends on many issues such as bandwitdh, latency, what kind of data you will be passing and what size. If you are planning on flipping through records (navigating one at a time) via datasets and don't happen to have T1 lines, it can get slow.
You mention in another post that you may also be using this over the Internet. I was going to use Web Services to communicate between my application and the SQL Server over the Internet passing DataSets. The internet connection is a SDSL line on one end at 384K/384K and a cable modem at the other at 1500K/128K. The web services were using Windows security.
Sometimes the first connection to the server via web services would take sometimes 2-3 seconds while a couple of times it took over 10 seconds.
Connecting to a running Sql Server directly in the code was sub-second and the same goes for fetching records.
I also had web services for posting images automatically that would range from a few K to 90K per imagine on matching DSL connections at 384K/384K. A seperate Web Service call was made for each imagine posted as a DIME attachment. It was tremendiously slow by doing it per image.
The server machine is very old technology and may be the reason for the slow response. It is only a PII450 with 256 megs of RAM.
Rocky Moore <><
|
|
|
|
|
Thanks for the feedback.
I have been researching the topic and have found allot of usefull information and performance statistics. You are correct in saying that it depends. What I get from this is that if I decide to use web services, I need to design them for actual usage behaviours and optimize them accordingly.
Thanks,
Matt Gullett
|
|
|
|
|
Hi!
Do you know how to do that?
I have a lot of objects. I want to serialize them, but some has not serializable attributes...
I want to create clones from the original objects dynamically.
How to solve this?
AgyklonN
|
|
|
|
|
Hi,
I wrote a simple C# service that uses remoting. It installs just fine, but for some reason when I try to start the service, I get the error message "Service 'SharpPrivacy OpenPGP Service' on 'local machine' could not be started. Error: 193 (0xc1)" (message was translated from german to english by me. It might not be exactly the same in english WinXP). I didn't find anything on the web about that error. Does someone know what might be the problem?
The service is generally the normal Service template, I only changed the function onstart:
<br />
protected override void OnStart(string[] args) {<br />
HttpChannel myChannel = new HttpChannel(4433);<br />
<br />
ChannelServices.RegisterChannel(myChannel);<br />
RemotingConfiguration.RegisterWellKnownServiceType(typeof(SharpPrivacy.SharpPrivacySrv.SharpPrivacy), "SharpPrivacy", WellKnownObjectMode.Singleton);<br />
}<br />
TIA,
Daniel
PS: If interested in SharpPrivacy (an OpenPGP implementation in c#), read my article[^] about it.
|
|
|
|
|
I had to go to Windows Components and Internet Information Services (IIS).
You are failing some kind of security check. If this works for you as it did me, you can then re-install IIS.
Good luck.
|
|
|
|
|
I don't quite understand. Do you know what kind of security check causes the error? And how would reinstalling IIS help?
Greets,
Daniel
|
|
|
|
|
I do not understand either. I am just telling you what we had to do.
We found this by comparing where the software worked and where it did not.
Sorry, it is a strange .NET world.
|
|
|
|
|
Hi && thanks for your answer. I set the installer to log on as the local system acount and as I am administrator, it should work, shouldn't it?
Anyway in the meantime I had a look into the event log, and there I found the corresponding error message: "SharpPrivacySrv is not a valid Win32 application".
I found a few references to that error on google (here[^]) but not a single solution to the problem.
Any ideas left?
Greets,
Daniel
|
|
|
|
|
I found the error. SharpDevelop (the IDE I use) sets the compiling target to a dll for a service, but it has to be an exe file.
As exe, it worked just fine. Thanks for your help!
Greets,
Daniel
|
|
|
|
|
Hi, Now I am confused with one question,
I have one computer(which hasn't a IP address for Internet) in the LAN,but I wanna develop one small applications to update the data which is stored in the SQL Server on one remote computer.I don't know whether I can connect to it.Do you know it? Tell me ,please.Thanks.;P
|
|
|
|
|
You would connect to it just like you do locally (assuming you are currently using TCP/IP to connect). Instead of the server name in your connection string you would use the IP address of the remote computer. Be sure to have port 1433 open in any firewalls you use.
If you are using Visual Studio .NET you can build the connection the same way as you do for your local machine except when it prompts for the server name enter the IP address. You need to be sure your connection string forces it to TCP/IP instead of named pipes.
Rocky Moore <><
|
|
|
|
|
Hey everyone,
As my first project with C#, DirectX, and object oriented programming begins to take form, I'm finding myself with a real problem. I only get to actually 'test' my game online once every few days because I don't know many people who will try it out with me.
On my LAN, the game runs perfectly fine. I can launch as many game clients as I want and everything appears smooth. Once I actually test it over the internet, it's a different story. When two clients connect, there appears to be some serious lag between them for a few minutes, but then it clears up and plays great - with a short lag between shooting someone and having them explode (depending on the players' ping). When a third person joins, everything goes to hell and never syncs up again.
I've tried using the DirectX network simulator but changing my game around using that has a guide is extremely frustrating. My last innovation (or desperate attempt) crashes my application under the sim, but a seems to work fine otherwise.
I'm getting nowhere without being able to test the game over the internet (or at least better simulated lagged environment).
I guess what I'm asking then, is there a .NET chatroom online where I could just pop in and try to round up a person or two? Or is there some kind of utility that I can use to simulate higher than 0 ping?
EvilDingo
|
|
|
|
|
server bandwidth and latency
<a TITLE="See my user info" href=http:
|
|
|
|
|
[rant]
One of the dependent assembly in my app updated to a new version. So I unloaded the old assembly reference from the solution and added new reference to the new version of the assembly.
Now the fun part started. Whenever I start the app, it crashed at class constructor. (both in debug and release)
Exception:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.
Additional information: File or assembly name System.Windows.Forms, or one of its dependencies, was not found.
Debugger MessageBox:
There is no source code available for the current location.
I banged my head for 30 minutes or so, I added every possible version of code to check the dependent assemblies loaded or not. But everytime I got the same error, eventhough I set the breakpoints.
Later I realized that I forgot remove the old control from the toolbox. So when I tried to add the new version of the control to the toolbox, I got this error
The assembly 'blah..\blah.dll' could not be loaded. Check that any dependencies the file requires are installed.
After 1 hour or so I came to know that the new version of assembly (control) is compiled with VS.NET version 1.1 and I am running VS.NET 2002. Argh!!!
.NET supposed to resolve the problems from DLL Hell right?, What am I missing?
[rant]
Thx for listening.
Never take a problem to your boss unless you have a solution. This signature was created by "Code Project Quoter".
|
|
|
|
|
I have the same concerns as you. For example, why is it, that if I download some demo code from an article, that contains a compiled exe, compiled with version 1.0, it crashes on my system which is 1.1?
This is all supposed to be compatible. What happens when a user tries to run my app on some future version say 2.0? Will it run? I am not too confident it will.
WTH?
Amber Star
Visit My WebLog..
|
|
|
|
|