Solved

remoting questions

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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