|
Hello, I`m making in Windows XP a Search Deskband [like the one in Vista] but i have a big problem: don't know how to get the current window address, so that it searches only in current folder and subfolders.
Thank you in advance!
|
|
|
|
|
curtuy wrote: the current window address
address??
could it be Directory.GetCurrentDirectory() you want?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
for a deskband Directory.GetCurrentDirectory() returns "C:\Documents and Settings\My user"
for ex: if i`m in D:\Games i want to get "D:\Games".
[Thanks for your fast responses ]
|
|
|
|
|
What is a window address?
|
|
|
|
|
Microsoft Way 1
Redmond
WA 98052, USA
I are Troll
|
|
|
|
|
window address: in IE is the place where you write a site's path, in Explorer is the current path.
|
|
|
|
|
Sometime back, I found this[^] link. Not that it is the solution to your problem, but I guess this is what you are looking for. Maybe someone who has used this method or is aware about this can help.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thanks very much .
|
|
|
|
|
Hello,
Im trying to make a multithreaded proxy tester/scanner.
http://i36.tinypic.com/2m5jllf.jpg[^]
here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WebProxyTest
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void Main_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
}
private void btnStart_Click(object sender, EventArgs e)
{
for(int i = 0; i < lstProxies.Items.Count; i++){
string proxy = lstProxies.Items[i].ToString();
string[] proxyinfo = proxy.Split(':');
string proxyhost = proxyinfo[0];
int proxyport = Convert.ToInt32(proxyinfo[1]);
WebProxyTest test = new WebProxyTest(proxyhost, proxyport, "http://google.com/");
ThreadPool.SetMaxThreads(10, 2);
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessProxies), test);
}
}
private void ProcessProxies(object state){
WebProxyTest test = state as WebProxyTest;
test.TestProxy();
lstResults.Items.Add("Result: " + test.ProxyResult);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
namespace WebProxyTest
{
class WebProxyTest
{
private string proxyhost;
private int proxyport;
private string url;
private string proxy_result = "none";
public string ProxyResult {
get {
return proxy_result;
}
set {
proxy_result = value;
}
}
public WebProxyTest(string proxyhost, int proxyport, string url)
{
this.proxyhost = proxyhost;
this.proxyport = proxyport;
this.url = url;
}
public void TestProxy()
{
try
{
WebProxy proxy = new WebProxy(String.Format("http://{0}:{1}/", proxyhost, proxyport), true);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = proxy;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string result = reader.ReadToEnd();
proxy_result = "Done: Got " + result.Length;
System.Windows.Forms.Clipboard.SetText(result);
response.Close();
reader.Close();
}
catch (System.Exception ex)
{
proxy_result = "Error: " + ex.Message;
}
}
}
}
the problem is at this line:
test.TestProxy();
and/or
lstResults.Items.Add("Result: " + test.ProxyResult);
when I call a function/property of the WebProxyTest class I get an exception with something like:
"Error: The current thread is the mode Single Thread Apartment (STA) be brought before OLE calls can be made. Verify that the main function STAThreadAttribute is highlighted."
any ideas?
Thanks in advance
modified on Sunday, October 11, 2009 1:10 PM
|
|
|
|
|
Hi,
there could be two issues:
1.
OptiPlex wrote: CheckForIllegalCrossThreadCalls = false;
IMO is a very bad idea. If you feel a need to disable those checks, something is fundamentally wrong. Please read this article[^].
2.
AFAIK a lot of (all?) COM components (and that includes the Clipboard) require to be handled only by threads that are in a "Single Threaded Apartment", which also is a way to obtain thread safety. You can get things right by either specifying [STAThread] in front of your public static Main() method (which is there by default IIRC), or by setting it explicitly on the relevant thread, using Thread.GetCurrentThread().SetThreadAppartmentState().
[EDIT]
As one can set the AppState only once for a thread, this may not work for ThreadPool threads; so you may have to create your own Thread(s) instead.
[/EDIT]
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
thanks allot for your reply.
I was checking out the link u posted, but it seems like thats for controls/ui operations only.
Now im still looking for other sollutions
thanks again
|
|
|
|
|
As I said earlier, using CheckForIllegalCrossThreadCalls is bad, whatever your app is, as it does not solve anything, it is completely useless (that is what the article is about). So you should fix that; and then do something about STA as I indicated.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
The project we are working on for school requires us to create a windows form in Visual Studio 2008. We have written the code for the database manager, dbHelper, employee and employee factory class. We do not know how to call the appropriate methods to the form. We are not allowed to put any code in the form other than get a appropriate methods. We are not using WPF.
|
|
|
|
|
Depends on the solution structure. If the UI is in separate project, then you will need to add the reference to the other projects in the UI project and the call the method.
In case everything is in same solution, you can call methods marked public/internal through creating objects of respective classes. In case of static methods, you can directly call the method using class name. If you have different namespaces in the solution, use fully qualified names.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hello,
The KeyDown even is:
<Occurs when a key is pressed while the control has focus.>
What if i want to see ALL key presses? not only when the control has the focus?
Thanks
|
|
|
|
|
|
On the main form there will be a property called Key Preview . Set that to true and the main forms KeyPress or KeyDown event (I'm not sure which) will be fired before the active control gets the event.
This property is only available on a windows form however, I'm quite sure it's not on any controls.
My current favourite word is: Sammidge!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
How can I do the following number 4 and 5 task using client server socket programming?
1. Client send a query as regular text to the server. [I can do this]
2. Server get the SQL from the client. [I can do this]
3. Server execute the query(Select statement). [I can do this]
4. Server return the query result as datatable or dataset to the client [How can I do this]
5. Client get the datatable or dataset and display to the client side.[How can I do this]
|
|
|
|
|
1. Don't write everything in bold. It's a plain message, so it's wise to use plain text.
dokhinahaoa wrote: Server return the query result as datatable or dataset to the client
Serialize it into XML, that should do the trick.
dokhinahaoa wrote: Client get the datatable or dataset and display to the client side.
Deserialize your dataset
I are Troll
|
|
|
|
|
Sorry !!!
Can I have sample code for that??
|
|
|
|
|
dokhinahaoa wrote: Can I have sample code for that??
You'd best start here[^], samples can be obtained here[^].
Basically, you transform an object into XML (or binary), send it, and rebuild the class on the receiving end. Something like this;
"Class X -> becomes XML -> gets send -> gets received -> receiver makes class from XML" Enjoy
I are Troll
|
|
|
|
|
Hi all
I would like to use Trace class or TraceListener to make code tracing in each thread at a different indendation level.
Function #1 From Thread#1
Function #2 From Thread#1
Function #1 From Thread#2
Function #3 From Thread#1
Function #2 From Thread#2
Function #3 From Thread#2
Most of Trace methods are shared so setting Trace.IndentLevel changes this value for all threads.
If I use 2 different objects for the same TraceListener, like for example ConsoleOutputTraceListener , there is no Thread safety guaranteed ( check IsThreadSafe for each object ).
Do you know some general approach to solve this issue?
Do I have to implement my own logger?
Kind Regards
Mn
|
|
|
|
|
One suggestion is to create a thread-safe singleton class.
As you create a thread you should register it with the singleton, which assigns it an indentation level.
Any trace statements should be made through a method on the singleton class, which can then resolve the indentation level.
When the thread ends, it is important to de-register it from the singleton.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Hello I want to open an exe file within a form of my Application .How can I do this?
if the file was not sizable what shoud i do?
thank you
tahereh sadeghi
|
|
|
|
|