|
Hello,
I have a data class in my Web Service server. Its name is User.
When I include this web service to the client and name it "WSA" the User class will be WSA.User.
the problem is when I serialize a User instance in client its type will be WSA.User and I can not deserialize it to a User instance in server. the types will be different.
What can I do?
|
|
|
|
|
Don't define User on both the client and server. Define User in a seperate dll, referenced by the service and client.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
Do you mean that...
I should define a User dll on server. And both webservice and client should reference them??
I haven't experience of dlls. will it not be a problem for client to reference a dll in remote server?
|
|
|
|
|
Create a dll that contains the User class.
When you build the client, add a reference to the dll containing the user class.
When you build the service, add a reference to the dll containing the user class.
The client doesn't need to reference a remote dll, the user dll can be copied locally to both client and service.
This way, both the client and service will be using the same object.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
Sorry, I'm a bigginer in C# , and i want to ask a trivial question , i get numbers from textBox as a string and i want to deal with it as an integr what i can do ?
misho
|
|
|
|
|
|
int n=Convert.ToInt32("123");
Check out all the Convert class static methods. Don't feel bad about not noticing this either--there's lots of these little hidden classes in .NET!
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I would like to open, manipulate (zoom and pan) a pdf file in a c# web app. Is this ppossible? Any examples out there?
Brian
|
|
|
|
|
All you have to do is server up the PDR file, just like any other .JPG, .GIF, or .DOC file. The client will handle the rest provided Acrobat Reader is installed.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
lets say i have a simple form with a button on it. let button1_Click() be the function binded by the eventhandler delegate.
the problem: i need this function to do a certain task that may take some time. i don't want this to freeze the UI(user interface) however i need to stop any further calls to button1_Click() for the duration of the task. sounds realy easy but to my surprise it's not that easy.
take the following examples of the button1_Click function bodys:
<br />
{<br />
this.button1.Enabled=false;<br />
this.button1.Enabled=true;<br />
}<br />
visualy disables the button but if you push it (even if disabled) X times the function will execute exactely X times.
<br />
{<br />
if(this.ignore)<br />
return;<br />
this.ignore=true;<br />
this.ignore=false;<br />
}<br />
same as above just that it doesn't visualy disable the button.
ideas, solutions and explanations apreciated.
|
|
|
|
|
I think you should consider porting the task you wish to do on a separate thread. This will not "freeze" your GUI since it will be running on a separate thread, other than the main (GUI) one.
By doing this, you could also specify that you wish to wait for your thread-processing to complete before executing the rest of your code.
If you haven't implemented multiple threads before, then may I suggest to Google it. A simple google search for something like "C# Thread tutorial" or "C# Multithreading" will bring up tons of results.
Hope this helps
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
the problem is not the freeze of the GUI. that i can simply avoid by multithreading as you pointed out. the issue is stopping any further calls of the function during the execution of the task.
i have run into this problem when i had a task that needs like about 500 miliseconds to run (more exactely it's a MoveNext). i decided not to multythread it since it's quite short. the problem is when a users starts pounding the NextButton with 20 clicks a second (it happend to my by accident in a test) the application starts to slow down since it's ordered to do like 20 tasks/second and it can only do 2/second. not to mention sometimes it has to acces sensible data that has to be locked down for thread safety purposes and it sometimes takes like 2-5 minutes for it to actualy recover. there are more issues here like race conditions and so forth.
now i thought that blocking any calls to the function would be the easyest way to do it. however it turned out not to be.
|
|
|
|
|
Why don't you simply disable the button and enable it after the operation completes? Something like
private void buttonClick(object sender, EventArgs e)
{
thisButton.Enabled = false;
DoLongOperation();
thisButton.Enabled = true;
}
If you can't enable/disable, you can have a flag to simulate it, set the flag to false before the operation and reset it after the operation. The function would then first check if the flag is true before proceeding.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
obviously you haven't payed attention to my first post. the first example does just that. disabling the button and enabling it after the task is done. however it doesn't behave as expected. Visualy the button is disabled, but the function executes as many times as you push the button, regardless of it's state (disabled/enabled). if you put a counter in it and look at it after the test you'll see it's nice and neat the number of clicks you made.
i think that this is because somehow it stacks the events and fires them after the function executes. try and run this code:
<br />
public void task()<br />
{<br />
Thread.Sleep(1000);<br />
this.counter++;<br />
}<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
this.button1.Enabled=false;<br />
Thread t=new Thread(new ThreadStart(task));<br />
t.Start();<br />
while((t.ThreadState & (System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Unstarted)) == 0)<br />
{<br />
Thread.Sleep(100);<br />
}<br />
t.Join();<br />
this.button1.Enabled=true;<br />
Debug.WriteLine(this.counter);<br />
}<br />
this has multi threading too. i can't exclude the possibility i'm doing something wrong but i can't seem to see where. pointers anyone?
|
|
|
|
|
Yeah, you're right. What's happening is after the button gets disabled, all the clicks keep getting added to the message queue and once your button gets enabled, they get dispatched to the button and so you keep getting the event as many times as the user clicked.
To prevent that from happening, just call Application.DoEvents() before enabling the button. That'll clear off all those click messages in the queue and therefore you wont get the Click event. Just do
public void task()
{
Thread.Sleep(1000);
this.counter++;
}
private void button1_Click(object sender, System.EventArgs e)
{
this.button1.Enabled=false;
Thread t=new Thread(new ThreadStart(task));
t.Start();
while((t.ThreadState & (System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Unstarted)) == 0)
{
Thread.Sleep(100);
}
t.Join();
Application.DoEvents();
this.button1.Enabled=true;
Debug.WriteLine(this.counter);
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
neat! works. thanks for the help
|
|
|
|
|
Alternatively, you could just decouple the event handler and then recouple it after the call.
|
|
|
|
|
yeah that crossed my mind too. but it seems a bit sadistic to me anyways.
funny thing is i knew about Application.DoEvents() and actualy used it .. but to no result. in my test i placed it in the while loop because normaly you want from time to time the app to respond to other calls but oddly it didn't work(no idea why thow).
the other thing that crossed my mind was to add a messageFilter before thread.Start and remove it after my task finished. but that's a bit too costly in my opinion.
|
|
|
|
|
put this as a class variable
<br />
private ThreadStart ts= new ThreadStart(urfunctionhere);<br />
private Thread t=new Thread(ts);<br />
then in ur button u could do
{<br />
<br />
button.enabled=false;<br />
<br />
if(t!=null&&!(t.isAlive))
{<br />
t.start(); <br />
}<br />
<br />
button.enabled=true;<br />
<br />
}
hope this help u
|
|
|
|
|
well for one your example doesn't work. mainly because that's not the propper way to test if a thread is running. however even if i correct that problem it still doesn't solve my problem because now you have to sincronize the started thread. if you will read my third post you'll see a sincronised example that well you guessed it .. doesn't stop the calls.
|
|
|
|
|
You may try the following method if it works (it apparently works on my machine; however I cannot test in your conditions).
As an event can be handled by more than one event handler, you may declare two event handlers for the same button click by using two different methods, as under:
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.Click += new System.EventHandler(this.button1_Click2);
It is pertinent to mention here that when an event is handled by more than one handler, all the methods handling that event are executed. The order in which the methods execute is the same as the order in which the association was created. Thus, in this case, "button1_Click" method will be executed first and thereafter the second method "button1_Click2" will be executed. What I suggest it that you disable the button1 in the first such method and do your long task in the second method. As by the time the second method starts, the first method must already have been executed (meaning that the button1 is now already disabled), you can safely do your long task in the second method. The code can be something like this:
private void button1_Click(object sender, System.EventArgs e)
{
this.button1.Enabled = false;
}
private void button1_Click2(object sender, System.EventArgs e)
{
this.button1.Enabled = true;
}
I am not sure, but I hope that your problem can be solved in this manner.
|
|
|
|
|
Hi all,
one big disadvantage (that's my feeling) of .Net-App is, the application startup delay on the first start (loading libraries etc.). I am going to write a "Do nothing Apps" which will be loaded on autostart, so that the libraries are in memory an the other applications will start faster.
.... or is there a much better way to improve the startingtime ?
Frank
|
|
|
|
|
That might work, until you load something that the OS decides is more important and frees up the unused, but still cached, libraries.
I guess I wouldn't bother. All you're doing is moving the problem around. Now you're computer will boot that much slower! And you still won't have solved your "first time load" time delay.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I have a new lunatic idea,
I write a VB6 app's, showing a pretty logo and the hourglass cursor, do a process-start of my .net app's and make a challange to the user to cook e new coffee, make two or three phone calls and than...... my app's still ready to work.
.... o.k we are in the Einstein Year - time is relative - if we move slower ... time goes faster or something like that.
That's another day of microsoft frustation.
Frank
|
|
|
|
|
Don't do it.
If you send the loading time to system startup, you will make it slower every time; and it's not every time that your users turn on their computer to use your app, is it?
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|