|
I have a class that when triggered downloads a file using the webclient class. The problem is my event AsyncCompletedEventHandler is never triggered when the file is finished downloading, never informing the user that the file is downloaded. Where did I go wrong?
public Download(string URL1, object send)
{
Sender = send;
Url = URL1;
WebClient client = new WebClient();
client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback2);
string[] s;
s = Url.Split(new Char[] { '/' });
string l;
System.Uri Uri = new System.Uri(Url);
l = @System.IO.Directory.GetCurrentDirectory();
l = @l + @"\" + s[3];
client.DownloadFileAsync(Uri, l);
}
public void DownloadFileCallback2(object send, AsyncCompletedEventArgs e)
{
//some code to inform user to run file or not...
}
|
|
|
|
|
Try scoping the WebClient variable at the class level and then assigning the DownloadFileCompleted EventHandler on first use. I think that since client is scoped only in the method it will begin the Async operation and then exit the method and client will go out of scope.
WebClient client = null;
...
public Download(string URL1, object send)
{
...
if(client == null)
{
client = new WebClient();
client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback2);
}
Keep It Simple Stupid! (KISS)
|
|
|
|
|
Hi Everybody!
I'm needing a software to rectify some images. I'm developing my thesis, however, despite the fact I have finished my project, my own software, I'm getting some errors because the images are not rectified.
My project is about a StereoVision, so from two images I have to process those images to get a 3D partial reconstruction. I have to give this project to my university this Thursday Nov 18th, so I'm getting desperated because I cannot get the results I was waiting for and it is because of that problem.
I will not use that code to add it to my project, I just need the software or application to rectify my two images.
If somebody have some information about where I can get this software or at least the code to compile, please help me!!
I'm needing it!!
Thanks a lot for your attention. I really appreciate it!
|
|
|
|
|
ANd what do you mean by "rectification"?? That can mean anything...
|
|
|
|
|
Image rectification is a transformation process used to project multiple images onto a common image surface. It is used to correct a distorted image into a standard coordinate system.
Stereo vision uses triangulation based on epipolar geometry to determine distance to an object.
Between two cameras there is a problem of finding a corresponding point viewed by one camera in the image of the other camera. (This is called the correspondence problem.) In most camera configurations, finding correspondences requires a search in two dimensions. However, if the two cameras are aligned to have a common image plane, the search is simplified to one dimension - a line that is parallel to the line between the cameras (the baseline). Image rectification is an equivalent (and more often used) alternative to this precise camera alignment. It transforms the images to make the epipolar lines (epipolar geometry) align horizontally (Oram 2001).
If the images to be rectified are taken from camera pairs without geometric distortion, this calculation can easily be made with a linear transformation. X & Y rotation puts the images on the same plane, scaling makes the image frames be the same size and Z rotation & skew adjustments make the image pixel rows directly line up. The rigid alignment of the cameras needs to be known (by calibration) and the calibration coefficients are used by the transform (Fusiello 2000).
In performing the transform, if the cameras themselves are calibrated for internal parameters, an essential matrix relates the relationship between the cameras. The more general case (without camera calibration) is represented by the fundamental matrix. If the fundamental matrix is not known, it is necessary to find preliminary point correspondences between stereo images to facilitate its extraction (Fusiello 2000).
Stereo images can also be taken with a single camera in motion. In this case the relationship of the images can have significant forward-motion components, and a linear transformation may produce severely warped images or very large images. Non-linear transformation techniques can be used to manage this difficulty (Oram 2001).
THIS DEFINITION WAS TAKEN FROM WIKIPEDIA at: http://en.wikipedia.org/wiki/Image_rectification[^]
It is a simple but very good definition about it!
Thanks!
|
|
|
|
|
I'm trying to kill some old and very bad habits and i would need some advice.
In my current project i am making a fluid dynamics simulator and i have a few big datasets.
All of the datasets are arrays containing around 50-100k objects.
There's a lot of code influencing the data so i prefer to structure it by calling functions that do specific things to the data, each function requires knowledge about most if not all datasets to do its calculation.
As things currently are the datasets are global variables that each function directly interacts with.
Being reminded that global variables are evil i want to remove them but i meet obstacles what ever i do.
If i don't keep the datasets as global i lose the data when the "Update" finishes.
If i do the calculations on a local dataset inside of Update i have no where to send the data for safe keeping because there are no global variables and once "Update" finishes its cycle everything inside it is purged.
I can't send the dataset to the next Update because because the Update call is done somewhere in the background.
I could write the datasets to the harddrive and then fetch it the next cycle but that seems awfully inefficient.
Maybe XNA is unique in this aspect but don't you have to use some kind of global variable in ordinary programming no matter what you do in order to keep the data persistent?
Confused
|
|
|
|
|
I've never used XNA (yet!) but in general - the singleton pattern is the normal answer to this. Loads of info on here and google about it.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'm from a VB background where weaning off globals is almost essential, however I think there are some cases where a global (static class in C# I presume) is valid and this certainly sounds like one, how else are you to persist your data between functions?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
One of the reasons why global variables are bad is because everything in the program has access to them.
While reading up on singletons there seem to be just as many threads with the subject "Singletons are evil" as there are "Global Variables are evil".
How should i interpret what seems to be a bias against any and all sorts of persistent data?
How do people usually fix things like...
1: "Shopping cart" in webapplications, everything doesn't need to have access to the shopping cart but unless you store the shopping cart as a global or singleton(static class) you're going to lose whatever was in it.
2: Texture storage in games, same problem here, the sound manager for example doesn't need access to the textures, but unless you store the textures somewhere in the higher scope you're going to lose it all when the sound manager starts.
Still confused
|
|
|
|
|
Hi,
I have a DGV that load´s a table from a xml file, but after i make changes i can´t save them, see bellow. Help me debug this
Class_Helper.DataSet_Xml = new DataSet();
Class_Helper.Assembly_This = Assembly.GetExecutingAssembly();
Class_Helper.Stream_Resource = Class_Helper.Assembly_This.GetManifestResourceStream(Class_Helper.ResourceXml_login);
Class_Helper.DataSet_Xml.ReadXml(Class_Helper.Stream_Resource);
DataRow DataRow_user = Class_Helper.DataSet_Xml.Tables[0].NewRow();
DataRow_user["id"] = 10;
DataRow_user["f_name"] = ToolStripTextBox_FName.Text;
DataRow_user["l_name"] = ToolStripTextBox_LName.Text;
DataRow_user["username"] = ToolStripTextBox_Username.Text;
DataRow_user["password"] = ToolStripTextBox_Password.Text;
DataRow_user["role"] = ToolStripComboBox_Role.Text;
Class_Helper.DataSet_Xml.Tables[0].Rows.Add(DataRow_user);
DataGridView_Administrator.DataSource = Class_Helper.DataSet_Xml.Tables[0];
Class_Helper.DataSet_Xml.WriteXml(Class_Helper.ResourceXml_login, XmlWriteMode.WriteSchema);
Thanks
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hi. I need to send a http link to a asterisk server. It will use that link to call a script that will make certain calls to the thelephones in the company. Could someone explain how can i open a connection to the asterisk server?
|
|
|
|
|
Hi all,
How can I call MFC-dialog from managed code?
I tried to do this using platform invoke service but application core dumps because assertions deep in MFC.
Please advice.
Thanks
|
|
|
|
|
|
i am trying to read from an xml document but am not having any luck getting selectsinglenode to work
here is the code i am using
XmlDocument xml = new XmlDocument();
xml.Load(str); //str has the path to my XML doc
XmlNode xmln = xml.SelectSingleNode("/GPO/Identifier/Identifier");
//xmln is always null but xml has my xmldoc loaded in memory
string Identifier = xmln.InnerText.ToString(); //code bombs here cuz xmln is null...
here is the first few lines of the xml
<?xml version="1.0" encoding="utf-16" ?>
- <GPO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.microsoft.com/GroupPolicy/Settings">
- <Identifier>
<Identifier xmlns="http://www.microsoft.com/GroupPolicy/Types">{89AEAFFE-E1F8-4786-8AF7-6BE2D991625E}</Identifier>
i have 20 XSD schema files that are related to the xml docs i am trying to parse but i'm new to xml and not clear on how to use the xsd's
help in either direction would be great!
|
|
|
|
|
Didn't you post this same question two days ago?
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
no my last question was using xpath, and not making any progress....
I guess I will stop posting on code project...
I'm not asking someone to write this for me, I just have something new and is not working was trying to get someone to help point out what i am doing wrong so i can move forward. sorry for reposting a different but similar question.
|
|
|
|
|
No, it is just working with those tools is just an absolute PITA and to help most of us would have to paste it into a project and fiddle unless the error just jumps out at us. I usually just use xsd.exe to create a class from the XML file and then serialize into the class rather than xpath since it is lazier and easier in .NET.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
i've never used xsd.exe before this project but when i tried to create my own xsd files from the xml it complained about to many nested tables. when i found the MS xsd files i tried to create classes but it is saying something about undefined complexType.
if there is a way I can use the MS xsd files then great if not i need to figure out how to parse this xml file the hard way and i know it is going to be a PITA.
|
|
|
|
|
Hi again,
The xml was missing some end tags so I added them to test this case. When I added a name alias on xmlns attributes it began to work. Here's the code I used. Note the aliases!
string testText = "<?xml version=\"1.0\" encoding=\"utf-16\" ?> <GPO xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:<big>Alias1</big>=\"http://www.microsoft.com/GroupPolicy/Settings\"> <Identifier> <Identifier xmlns:<big>Alias2</big>=\"http://www.microsoft.com/GroupPolicy/Types\">{89AEAFFE-E1F8-4786-8AF7-6BE2D991625E}</Identifier></Identifier></GPO>";<br />
<br />
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();<br />
xml.LoadXml(testText); <br />
System.Xml.XmlNode xmln = xml.SelectSingleNode("/GPO/Identifier/Identifier");<br />
string Identifier = xmln.InnerText.ToString();
Hope this helps you forward,
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
thanks for the tip but the xml code i don't want to change it is an export that i want to import to a database
|
|
|
|
|
|
XmlNode root = xmlDocument.DocumentElement;
for (int i = 0; i < root.ChildNodes.Count; i++)
{
XmlNode node = root.ChildNodes[i];
if (node.Name == "NAME")
{
}
}
|
|
|
|
|
add http://www.microsoft.com/GroupPolicy/Settings to a new xml namespace manager and use it with your node select. Something like:
XmlNamespaceManager NSM = new XmlNamespaceManager(YOURXMLDOCOBJINSTANCE.NameTable);
NSM.AddNamespace("some_random_name_like_abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode whateverNode = YOURXMLDOCOBJINSTANCE.SelectSingleNode("//some_random_name_like_abcd:WhateverElement", NSM);
XPath will generally not work without specifying the namespace, when a namespace is defined.
|
|
|
|
|
thanks, i just tried this and making some progress now
here is what i have to get the text of the whole node and the first child
XmlDocument xml = new XmlDocument();
xml.Load(str);
XmlNamespaceManager NSM = new XmlNamespaceManager(xml.NameTable);
NSM.AddNamespace("abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode xmln = xml.SelectSingleNode("//abcd:Identifier", NSM);
if (xmln.HasChildNodes == true)
{
if (xmln.FirstChild.Name == "Identifier")
{
this.textBox2.Text = xmln.FirstChild.InnerText.ToString();
}
}
this.textBox1.Text = xmln.InnerText.ToString();
is there a better way to do this or should i get coding?
and thanks to everyone!!!
modified on Thursday, November 13, 2008 4:15 PM
|
|
|
|
|
rather use /abcd:Identifier/abcd:Identifier to get only the child nodes labeled "Identifier" of the root "Identifier" node. Use the full power of XPath if you went that way ... w3 has a great tutorial on how to use them "productive" ... http://www.w3schools.com/XPath/xpath_syntax.asp[^]
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|