[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

remoting questions

Posted on 2004-10-05
5
Medium Priority
?
202 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

649 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