Solved

remoting questions

Posted on 2004-10-05
5
198 Views
Last Modified: 2010-04-15
Hi!

I often build my classes like this:
      public class User
      {
            private string username="";
            private string password="";
            public bool GetUser(int userid)
            {
                  try
                  {
                        //get username and password from database
                        //assign private string username and private string password
                        return true;
                  }
                  catch
                  {
                        return false;
                  }
            }
            public string UserName
            {
                  get{return this.username;}
                  set{this.username = value;}
            }
            public string Password
            {
                  get{return this.password;}
                  set{this.password = value;}
            }
            public bool UpdateUser(int userid)
            {
                  try
                  {
                        //update database with this.username and this.password
                        return true;
                  }
                  catch
                  {
                        return false;
                  }
            }
            public bool CreateUser(int userid)
            {
                  try
                  {
                        //save this.username and this.password as new post in database
                        return true;
                  }
                  catch
                  {
                        return false;
                  }
            }
      }

But now I'm making a project that uses remoting and I think that it may cause some problems.

Some background to the project if it may help:
The classes in the project are made in VB.NET because they interact with a program that isn't build to be accessed from C#(I tried but had to abandon it quite quick), I have also made an Interface in C# for the VB.NET project and the "listning server" and clients is also made in C#.
The VB.NET class has properties that get/set datatables, integers and strings.

My concern, (it just hit me..) is that SingleTon calls share info between clients and that may cause big problems with data being mixed up!?
Let's say that the client does this:

IUser user;
user=(IUser)Activator.GetObject(typeof(IUser),Convert.ToString(ConfigurationSettings.GetConfig("User")));
user.IUserName = txtUsername.Text.Trim();
user.IPassword = txtPassword.Text.Trim();
if(user.IUpdateUser(Convert.ToInt32(txtUserID.Text)))
      MessageBox.Show("User updated");
else
      MessageBox.Show("User NOT updated");

That is no problem, but what if 10 users do it at the same time?
I guess there's risk that data may be mixed up?
How can I solve this?
0
Comment
Question by:aleborg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Expert Comment

by:123654789987
ID: 12235096
0
 
LVL 3

Accepted Solution

by:
skpatra earned 500 total points
ID: 12236299
I can suggest 3 options (3rd one requires least effort):

1. Provide a wrapper remote class around such classes. Let this class be completely stateless and accept the values in methods. You can have a class called UserProcessor and provide method like .Add(UserName as String, Password as String). Let this method instantiate/invoke User class to perform the operations.

2. Best approach is to redesign the solution. Have a data class called UserDate with getters and setters for name/password. Make this a Serializable class. Have a User Manager which is a remote object accepting this user class for all the operations.

3. The option with least possible effort (but highest overload) is to invoke the remote components as client-activated objects in stead of singleton objects. You can checkout the method RemotingConfiguration.RegisterActivatedClientType to register a client activated object. Check the following article.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeremotingremotingconfigurationclassregisteractivatedclienttypetopic.asp
0
 
LVL 3

Expert Comment

by:atxondo
ID: 12248264
Why don´t ypu use the lock() sentence to stop these problems.
The lock sentence is a simple sentence that locks a variable until the sentences that must be executed during this lock sentence.
You must use a static object, that is unic in all the calls to that function. If the object is sattic and singleton you can use any object you want.
For example why don´t you try;

lock(database object)
{
     // Sentences that must be executed during the lock of the object
}

Lock() will stop any thread if another thread is inside the lock sentences.
0
 

Author Comment

by:aleborg
ID: 12254191
skpatra -> Can you provide an example to your second solution?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question