|
The caller is not passing just the string value. He/she is calling the property setter with a string value. In the call func(this) the this pointer takes the place of the mt in the Lambda Expression.
Personally, I wouldn't do it that way. The properties are public, so they can just as well be assigned directly. And if something goes wrong, you have at least a chance to debug the intermediate states when you use seperate statements instead of putting all into one.
|
|
|
|
|
Hi I am working on file io and am getting an io exception the process cannot access the file it's in use by another process.
I tried to closed all streams. I'm baffled please help.
Here is my code:
DateTime dt = DateTime.Now.Date;
try
{
string fileLocation = "C:\\pprdate.txt";
FileStream fs = null;
if (!File.Exists( fileLocation ))
{
using (fs = File.Create( fileLocation ))
{
fs.Close();
fs = null;
}
}
string line = null;
TextReader readFile = new StreamReader(fileLocation);
while (true)
{
line = readFile.ReadLine();
if (line != null)
{
DateTime sd = DateTime.Parse( line );
if (dt >= sd.AddDays( 16 ))
{
sd = sd.AddDays( 30 );
StartDate.Text = sd.ToShortDateString();
EndDate.Text = sd.AddDays( 30 ).ToShortDateString();
}
readFile.Close();
readFile = null;
}
else
{
TextWriter writeFile = new StreamWriter(fileLocation);
DateTime sd = dt.AddDays( 7 );
writeFile.WriteLine( sd );
StartDate.Text = sd.ToShortDateString();
EndDate.Text = sd.AddDays( 30 ).ToShortDateString();
writeFile.Close();
writeFile = null;
}
}
Frazzle the name say's it all
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
John F. Woods
|
|
|
|
|
If I'm looking correctly, you try to open a StreamWriter to the same fileLocation you already have opened a StreamReader .
For example if the line variable is null, you don't close the reader since it's inside the if statement:
...
if (line != null)
{
DateTime sd = DateTime.Parse( line );
if (dt >= sd.AddDays( 16 ))
{
sd = sd.AddDays( 30 );
StartDate.Text = sd.ToShortDateString();
EndDate.Text = sd.AddDays( 30 ).ToShortDateString();
}
readFile.Close();
readFile = null;
}
else ...
You didn't explain the overall idea you're trying to accomplish so I'm not able to sae what would be a good correction to the code, but I encourage to use using[^] statement to ensure proper disposing etc.
|
|
|
|
|
frazzle-me wrote:
if (!File.Exists( fileLocation ))
{
using (fs = File.Create( fileLocation ))
{
fs.Close();
fs = null;
}
}
This is utterly useless. There are options when opening a file that will create it if it doesn't exist already, so creating the file, just to close it is pointless.
Secondly, the using statement will automatically Dispose (which calls Close on a file oject) when the using block exits. So calling Close and then setting fs to null just duplicates code that is already there.
|
|
|
|
|
There are so many problems with your code here, but the issue you are seeing is because you are using the same file to read from and write to.
|
|
|
|
|
Hi guys . i'm working on a small project , is related to a socket programming . it's kind of chat program just we have one server and plenty of client . i have done every thing right . and im getting the result in the message box when a client sent me sth . but the problem is here when i'm trying to just put the string or the word that the client sent me into a textbox , it'll give me an error and i know wht it give me this kind of error , im using a while loop into my server program so when i start the program it get stop(hang) till get the message of the client so i figure out to run it into a new thread . i think you get the idea why this kind of error is appear to me , so i just decide to use the delegate the code its like this .
Thread thr;
public delegate void Dosth();
string sth = "";
private void buttonX1_Click(object sender, EventArgs e)
{
thr = new Thread(Listen);
thr.Start();
}
void Listen()
{
Soc.Bind(ipend);
Soc.Listen(10);
byte[] data = new byte[500];
while (true)
{
Socket client = Soc.Accept();
client.Receive(data);
sth = Encoding.ASCII.GetString(data);
athreadedfunction();
.
.
.
}
}
public void writeintotext()
{
textBox1.Text = sth;
}
public void athreadedfunction()
{
Dosth writeinto = new Dosth(writeintotext);
textBox1.Invoke(writeinto);
}
what do i need to know is how the invoke + delegate done sth and let the error disapear .
and i know the delegate is kind of pointer to the method or functions .
but what does mean of the invoke here ?
and how this error ("Cross-thread operation not valid: Control 'textBox1'") didnt appear to me when i used this piece of code.
plz help me in that i want to know how that done .
and im sorry about my poor english .
|
|
|
|
|
In Windows forms, you can access a UI control only from the same thread that created it. Accessing it from any other thread throws a Cross thread operation exception.
So, what Control.Invoke essentially does it to call the method passed to it using the thread that created the control.
|
|
|
|
|
Hello everyone,
I started to build WPF app the that one of the fuctions is loding html file into WebBrwoser control.
* the html file is file that i created (local on my pc)
my problem is that when i use WebBrowesr.Nevigate(path to html file) , i need to pass to the html 2 strings.
can anyone suggest a way for pass this 2 string to the html?
is there any way in html to read variables from my c# code?
hope i was clear enough.
Thanks alot !
|
|
|
|
|
How is the html file "expecting" the variables? As a query-string? How would you pass the data in a real webbrowser?
|
|
|
|
|
Hi,
i am trying to use WebBrowser.navigate("c:\path?pramaters").
so it should send the parameters like in GET method - as part of the address.
but it seems like there is a problem with the '?' char.
i also used the followig way:
String postdata = "long1=32";
System.Text.Encoding a = System.Text.Encoding.UTF8;
byte[] byte1 = a.GetBytes(postdata);
webBrowser1.Navigate("c:\\map.htm","", byte1, "Content-Type: application/x-www-form-urlencoded\r\n");
then i the map.html i m getting the parameters using javascript but the results of the parametrers is "undefined"
when i m trying to load the same html file (map.html?lat=12) directly in my chrome browser it getting the parameter as i pass him - 12 .
so the problem is the C# code , the javascript works well
|
|
|
|
|
Queryvalues are usually used from PHP or ASP, not from raw HTML. Fortunately, it's also possible using JavaScript[^].
|
|
|
|
|
Thanx Eddy but i already done it.
but this is not solves the problem.
the problem the when i m using the Nevigate mathod of the WebBrowser control , its looks like the parameters are not pass.
the javascript code is returing "undefined" values for the parameters.
so if i m navigate to : map.htm?lat=12 using the WebBrowser control.
the value of lat is return "undefined"
but if i m using my chrome browser end putting the same : path/mat.htm?lat=12
than the value of lat is return 12 by the javascrip code.
so the problem is with the WebBroser contorl.
any suggestions ?
|
|
|
|
|
amiraf123 wrote: so the problem is with the WebBroser contorl.
any suggestions ?
I'd suggest that it's not the webbrowser-control. See working example below;
[STAThread()]
static void Main()
{
using (var f = new Form())
using (var wb = new WebBrowser())
{
wb.Dock = DockStyle.Fill;
f.Controls.Add(wb);
wb.Navigate("http://www.google.com?q=test");
f.ShowDialog();
}
}
That passes arguments, simply using the "navigate" methods. Is there a COM-control on your HTML-page? Does the user have permission to execute untrusted JavaScript? Any exceptions thrown? Who/which API is used to draw the map? Does it work from a webserver (like 127.0.0.1), as opposed trying to navigate to a local file?
|
|
|
|
|
Hi,
i m using : webBrowser1.Navigate("E:/map.htm?long1=12&lat=12");
the map is drawing by google maps API
again: if i paste this link (E:/map.htm?long1=12&lat=12) into my chrome browser its work perfect!
but when using the webbrowser contor i got nothing.
this is local file.
this is realy crazy , i just cant find the reason for this problem.
|
|
|
|
|
amiraf123 wrote: again: if i paste this link (E:/map.htm?long1=12&lat=12) into my chrome browser its work perfect!
That's hardly the same; the WebBrowser is based on IE, not on Chrome. If you want to use Chrome as a control, you'll have to download the Awesomium component.
The WebBrowser control would also adhere to the security-settings of IE - check whether JavaScript is enabled.
|
|
|
|
|
Hi Eddy,
I solved the problem by uploading the map.htm file to free web server.
It seems like the problem was becouse the i tried to Navigate to the file on my local machine.
So now the Navigate method is path is to the file on the server.
Thanks !
|
|
|
|
|
I am new to WCF REST service and Bing Map APIs...
Can anyone please tell me where to start... I got the Bing Map key... Where do I (which namespace) find the Bing Map APIs (Routes API etc) and add to my project reference?
Thanks.
|
|
|
|
|
Don't repost. It's a weekend - have a little patience!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
|
Richard,
Thanks for the links... I read those links... But they don't explain which namespace or dill file I have to reference etc... I just need a quick tutorial how to use the BIng Maps Route APIs ... Thanks
|
|
|
|
|
Vijay Kanda wrote: I just need a quick tutorial how to use the BIng Maps Route APIs I am afraid that you will have to look for it yourself. This site exists to help people with specific technical problems, but we do not have the time (or in my case the skills) to provide tutorials on every subject in the IT field.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I am creating a REST Service project (just for learning purpose) and using Bing Map... This is what I want to accomplish...I am sending my current location (Latitude and longitude) to the service and I want to find out all the nearest Mac Donalds (for example) within 1 mile range from my current location and the distance and the time it will take me to get each Mac Donalds... I know there are BING MAP APIs which I can use to accomplish ...
But I never used BING map or rest service before... so can anyone please tell me the Bing Map method/API names which take latitude and longitude as argument and retrun the info that I mentioned above.
Thanks.
|
|
|
|
|
Have a look at Sacha Barber's his zombie article covers most of what you are after.
You can find the article here on CP. I would post a link but I'm writing this on a phone
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Simon,
Thanks... really appreciate it... I could not find the article which you mentioned... please let me know the url when you have a chance...
Thanks again.
|
|
|
|
|