|
I have a problem when reading a Streamreader object into a string:
<br />
private string GetStringFromURL(string url)<br />
{<br />
string strOut = "";<br />
<br />
HttpWebRequest webRequest;<br />
HttpWebResponse webResponse;<br />
Stream responseStream;<br />
webRequest = (HttpWebRequest)WebRequest.Create(url);
webResponse = (HttpWebResponse)webRequest.GetResponse();
responseStream = webResponse.GetResponseStream();
string responseEncoding = webResponse.ContentEncoding.Trim();<br />
if (responseEncoding.Length == 0) responseEncoding = "us-ascii";<br />
StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.GetEncoding(responseEncoding));<br />
<br />
sr.BaseStream.ReadTimeout = 3000;
try<br />
{<br />
strOut = sr.ReadToEnd();<br />
}<br />
catch (WebException ioe)<br />
{<br />
MessageBox.Show(ioe.Message.ToString());<br />
}<br />
<br />
<br />
webResponse.Close();<br />
responseStream.Close();<br />
sr.Close();<br />
<br />
<br />
return strOut;<br />
<br />
}<br />
<br />
The above code doesn't cause the Messagebox to actually pop up. When I pause the code I find it spends alot of it's time in the catch() area though. On closer inspection of the 'sr' object, it seems to have a problem:
<br />
BaseStream = Cannot evaluate expression because a native frame is on top of the call stack.<br />
Is there a way of checking for this error with an 'if' statement so that this process doesn't take so long? (it does eventually time out but this is v. slow. The url I'm reading into the string is:
http://www.atomintersoft.com/products/alive-proxy/proxy-list/?p=4[^]
Any help or advice much appreciated!!
Gerry
|
|
|
|
|
I see that you set the ReadTimeout on the response stream, but that is the timeout for reading data from the stream, not the timeout for ding the request.
Set the Timeout property in the HttpWebRequest object before calling GetResponse .
---
single minded; short sighted; long gone;
|
|
|
|
|
Good Day Sir/Maam,
I have a ListView on my program and it has 3 columns.
I add items in the end of the List. Using .add(); command. But when the list is gets too much item, the vertical scroll bar will activate.
What I want is to FOCUS the ListView on the Last item added. So that the last item will not be hidden from view. (You need to click the vertical scroll bar to view the last item)
Thank you.
|
|
|
|
|
Use EnsureVisible() [^] to ensure a specific item (in your case, the most recently added one) is visible.
/ravi
|
|
|
|
|
Cool. It worked as expected. Thank you sir Rabi!
|
|
|
|
|
Hi Sirs,
I want to know how can we unpack the C# dll files i mean i want to c all the classes in all namespaces like System.IO etc. in java we can easily do it but i don't know how can we do it in .NEt please help me in this regard..
thanx.
Pravo
|
|
|
|
|
Hi,
if you use Visual Studio, once you add a reference to a DLL and the corresponding
"using" statement, Intellisense will show you all available methods, fields, ...
The "Refector" tool by Lutz Roeder[^]
is in many ways similar to the "jad" tool that you are familiar with.
|
|
|
|
|
thanx a lot Luc Pattyn for answering , but actually i want to c the code of the classes in dll like code of Button class and so on so that i can c whats written in it . Same we do in java with javadecompiler, so please let me know how can i do it.
thanx
Pravo
|
|
|
|
|
Hi there, check out the VS addin Reflector, this gives you what you're after
regards
Pete Kane
|
|
|
|
|
sorry I didn't see Luc's post
|
|
|
|
|
Hi,
I got a piece of heavy duty code, which makes my app look frozen.
So i added threads so the GUI stays normal, now i want to add a progressbar.
But i cant call progressbar1.performstep() from the seperate thread,
After some looking i found out that i have to invoke (i think) but i have no idea how to do that,
i found some textbox examples and i just dont get them.
Thanks!
|
|
|
|
|
Hi,
Yes, Invoke() is what you need.
There are many examples in the articles on this site.
For one, look at my Sokoban article (the pasteOneMove method).
|
|
|
|
|
hi sirs n madams
i m very new with c# and want to learn everything ebout it
can u please provide me with some code snippets!!!
|
|
|
|
|
There are thousands of articles here, a lot of them about C#.
some examples[^]
|
|
|
|
|
Hi all,
Is it possible to do down-casting? If so, how?
Example:
Public class A
{
}
Public class B : A
{
}
Void main()
{
A a = new A();
B b = (B)a; // <-- down-cast, a run time error.
}
Thanks in advance.
|
|
|
|
|
No you can not: it would require an existing object (a) to suddenly become larger
(in case B has more data members, more methods, than A); this is impossible.
The one time "downcasting" is allowed is when reducing the capabilities, as in
int i=1234567;
short s=(short)i;
|
|
|
|
|
i need to a event for my form as lostfocus
123
|
|
|
|
|
Control.LostFocus
and
Form : Control
|
|
|
|
|
the form is not has loastfocus
123
|
|
|
|
|
Form extends Control
|
|
|
|
|
I've been looking at Matias' Half Keyboard and 503 Keyboard (http://www.matias.ca/halfkeyboard/index.php) and it seems like a rather neat idea. However, I'm not willing to spend $100 to find out I don't like it. So, I decided to try making a program/windows service that would intercept any keystroke, and via a configurable mapping, pass the mapped key on to windows. The remapping of keys, I can do. What I need help on is how to trap keyboard signals from getting to windows, and then sending the ones I want through. If anyone has suggestions, pointers, or links to articles about this kind of thing, please share.
I might consider working with others on this project as well. I've always wanted to try a colaborative project, and put out some open-source apps.
A soft glow comes from the pit in the darkness.
The clicking noise become faster - and louder.
A wind begins to stir up from the pit, as the
creature flexes it's wings, preparing for flight.
You stare into the pit, and hear a voice say
in your mind, "If you survive the encounter,
declare it to the world."
The Code Demon Rises.
|
|
|
|
|
You will need to install keyboard hook. Search google and/or codeproject for this term and you will find what you need.
|
|
|
|
|
To reproduce, run the code.
Observed: Form is shown
Expected: message box should displayed.
How to fix ?
Andrus.
using System;<br />
using System.Windows.Forms;<br />
using System.IO;<br />
<br />
class main {<br />
<br />
[STAThreadAttribute()]<br />
<br />
public static void Main() {<br />
File.Delete("c:\\test");<br />
using (FileSystemWatcher watch = new FileSystemWatcher()) {<br />
watch.Path = "c:\\";<br />
watch.Filter = "test";<br />
watch.Created += new FileSystemEventHandler(OnChanged);<br />
watch.Deleted += new FileSystemEventHandler(OnChanged);<br />
watch.Changed += new FileSystemEventHandler(OnChanged);<br />
watch.EnableRaisingEvents = true;<br />
}<br />
FileStream oFs = new FileStream("c:\\test", FileMode.CreateNew, <br />
FileAccess.ReadWrite);<br />
StreamWriter oWriter = new StreamWriter(oFs);<br />
oWriter.Flush();<br />
oWriter.Close();<br />
oFs.Close();<br />
File.Delete("c:\\test");<br />
Application.Run(new Form());<br />
}<br />
<br />
static void OnChanged(object sender, FileSystemEventArgs e) {<br />
MessageBox.Show(e.FullPath + e.ChangeType.ToString());<br />
}<br />
}
Andrus
|
|
|
|
|
Hi,
AndrusM wrote: using (FileSystemWatcher watch = new FileSystemWatcher())
so you dispose of the FileSystemWatcher and expect it to continue working for you ?
|
|
|
|
|
Dear all,
I've got a problem that I just cannot figure out. I must have tried just about everything. I'm hoping that one of you can help me out here.
My main application has got a form referenced, like this :
private Control control1;
This will allow me to call a method inside the form Control , like this :
private void Click(Object sender, EventArgs e)<br />
{<br />
control1.Method();<br />
}
Works perfect. The method on the form Control is executed.
The problem :
I created another form , that I call from inside the form Control :
private void Click_button(Object sender, EventArgs e)<br />
{<br />
ChildForm child = new ChildForm();<br />
child.Show;<br />
}
In that child form I also have got the same Control form referenced, because I want to call the same method exactly the same way as I would from the main application :
private Control control1
and a method to call the method on the Control form.
private void InvokeMethodOnControl()<br />
{<br />
Control.Hello = "a value";<br />
control1.Method();<br />
}
Only the value Control.Hello is passed back to the Control form ( in which I have a public string referenced ( public static string Hello; ) but the Method ( control1.Method() ) is not executed.
Can anyone tell me what I am doing wrong ? .. this is giving me a headache.
Kind regards,
|
|
|
|