|
Can anyone explain this line in plain english (I am learning).
var userCallback = e.UserState as Action<bool>
I understand how to call a typical invoke method on an action but how is e.UserState convertable to an Action<bool>? From what i have seen in object browser e.UserState is just calling a property.
When i right click on the property and select get definition this is the property it is referring to.
In this case UserState is from
System.ComponentModel.AsyncCompletedEventArgs
public object UserState
{
get;
}
Thanks for your time .
|
|
|
|
|
|
Snap!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Snap as in crackle and pop,
|
|
|
|
|
Children's playing card game[^], used for teaching number recognition etc.. Both turn a card over at the same time and if both are the same e.g. a 9 then the first to call out 'Snap' wins all cards laid down so far. Winner is one who gets all cards or most in a given time.
So 'Snap' is used when two people do the same thing at the same time.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for clearing that up for me.
For me the association was more like when some fragile part in ones mind breaks and you "snap".
|
|
|
|
|
I am just looking for a simple answer to the question thats all
|
|
|
|
|
Please do NOT post the same question in more than one forum. Very rude.
Please delete this one.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
ok i deleted it from ask a question section. so does anyone know the answer?
|
|
|
|
|
Great! After I went through all the trouble editing your question you decide to delete it.
Isn't life a bummer!
|
|
|
|
|
so i guess no one knows the answer..oh well
|
|
|
|
|
SciGama wrote: var userCallback = e.UserState as Action<bool>
Your question is little bit confusing for me. whatever
If a class supports multiple asynchronous methods, or multiple invocations of a single method
then UserState property is used to determine which task raised the MethodNameCompleted event by checking the value of UserState property
|
|
|
|
|
Why can't I do the serialization successfully? I get an execption at the serialize line, yet I can do this using BinaryFormatter and SOAP Formatter. What am I missing?
public class person
{
public person() { ;}
public string firstname;
public string lastname;
public int Age;
}
public class persons
{
public persons() { }
public ArrayList personlist = new ArrayList();
}
<pre>[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
person p = new person();
p.firstname = "Tim";
p.lastname = "Duncan";
p.Age = 34;
persons ps = new persons();
ps.personlist.Add(p);
FileStream fs = File.Create("C:\\Temp\\test.xml");
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
xs.Serialize(fs,ps);
}
|
|
|
|
|
I think that
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
Should be
XmlSerializer xs = new XmlSerializer(typeof(persons));
and persons should have the Serializable attribute.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
your suggestion did not work. I still get an InvalidOperationexception at the serialize line! The exception says "unable to cast an object of type xmlSerialization.persons to type system.collections.Arraylist".
modified on Tuesday, December 14, 2010 8:24 PM
|
|
|
|
|
Software2007 wrote: unable to cast an object of type xmlSerialization.persons to type system.collections.Arraylist
Just use List<Person> for the collection of person in place of ArrayList .I think that will work.
|
|
|
|
|
your suggestion worked. The 2 samples below worked. Could you tell me why I can't use ArrayList though? Is there anything else I need to do to get Arraylist to work, or does it just not work?
Thanks
public List<person> personlist = new List<person>();
...
...
XmlSerializer xs = new XmlSerializer(typeof(persons));
xs.Serialize(fs,ps);
OR
public List<person> personlist = new List<person>();
.....
.....
XmlSerializer xs = new XmlSerializer(typeof(List<person>));
xs.Serialize(fs,ps.personlist);
|
|
|
|
|
Software2007 wrote: Could you tell me why I can't use ArrayList though?
You could use it, But I just was giving you a alternate way of accomplishing task.
See THIS[^], You might get idea on how to use ArrayList Serialization.
And for the serialization I think second one is appropriate.
|
|
|
|
|
When you get exceptions of a 'general' type like InvalidOperationException it is important to investigate the Inner Exception to determine the exact cause.
Just in case you do not know how to do this. When the Exception dialog pops up look below and to the left of the main 'Troubleshooting Tips' box and you will see a 'View Detail' link under 'Actions'. Click it. Expand the 'Inner Exception' node and you will see lots of useful stuff.
The important one in this case is the Message, which before making the changes I suggested said that "it was unable to convert persons to an ArrayList " and after making the changes said "person was unexpected and that use of XmlInclude attribute was recommended".
Following this up led me to Troubleshooting Common Problems....[^] on MSDN.
Have a read and see if it helps you to resolve your problem. If not, I have the solution so post a message and I'll explain it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Ok,got it. Basically I needed the syntax like the following. I need to do some more reading I guess.
Type[] extraTypes = new Type[1];
extraTypes[0] = typeof(person);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList), extraTypes);
Thanks
modified on Wednesday, December 15, 2010 9:34 AM
|
|
|
|
|
|
public class Program
{
[Serializable]
public class person
{
public person()
{
;
}
public string firstname;
public string lastname;
public int Age;
}
[
XmlInclude(typeof(person))
]
public class persons
{
public persons()
{
}
public ArrayList personlist = new ArrayList();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
person p = new person();
p.firstname = "Tim";
p.lastname = "Duncan";
p.Age = 34;
persons ps = new persons();
ps.personlist.Add(p);
FileStream fs = File.Create("C:\\Temp\\test.xml");
XmlSerializer xs = new XmlSerializer(typeof(persons));
xs.Serialize(fs, ps);
}
}
The List<whatever> solution works because a generic List is strongly typed. It returns an instance of a 'whatever' when you index into it. ArrayList however, returns an instance of Object and the serialization code cannot, for whatever reason, resolve the object into a person.
Using XmlInclude , very rough potted explanation here , says "Hey I'm using instances of person in here somewhere, so if you find something you can't resolve, try person before bombing out."
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks. Your solution there was working for me. The problem was when I do
XmlSerializer xs = new XmlSerializer(typeof(ArrayList)); with or without the XMLInclude attribute, was not working!
the code shown here made it though.
Type[] extraTypes = new Type[1];
extraTypes[0] = typeof(person);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList), extraTypes);
|
|
|
|
|
Software2007 wrote: The problem was when I do
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
with or without the XMLInclude attribute, was not working!
That's because you are not serializing an ArrayList directly. You are serializing an instance of persons which happens to contain an ArrayList.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
It makes sense! Sorry for the confusion.
|
|
|
|