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
Solved

remoting questions

Posted on 2004-10-05
5
196 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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