|
System.UnauthorizedAccessException is almost thrown, when you try to change a file which is allready in use.
for example:
1. Assembly.Load( test.dll)
2. ... // do something
3. File.Delete(test.dll),while application is still running
--> Exception --> so you need to unload the assembly.
for this you have to use an AppDomain.Unload(...)
but I have the same problem too. so I can't really help you at the moment. use everything like AppDomain.Create, .Load,... maybe you find a solution. I would also need it.
thx
Christian
|
|
|
|
|
I finally found why. The assembly was a ServicedComponent (COM+). I was trying to load an assembly that had the same print as in COM+. This is now fixed.
Still have a problem to fix (SerializationException) but I'm on my way for this one.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Hi, I need to implement my own MouseHover event for a library I'm working on.
What is the exact logic of the MouseHover event? I can't find this on MSDN...
It seems like the MouseHover is fired only after the first N milliseconds that the mouse is idle in a control, and perhaps only if the control has focus. I expect I'd set a Timer when the MouseMove event is fired, and then invalidate the Timer if the MouseMove event was fired before N milliseconds had elapsed.
|
|
|
|
|
Arun Bhalla wrote:
I need to implement my own MouseHover event
Why? It's built into WinForms.
If you really need to roll your own, try TrackMouseEvent[^].
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'm writing a library of lightweight control-like objects which paint themselves on controls, such as Panel. I need to mimic MouseHover for these control-like objects. If I use Panel's MouseHover event, I only get the hover event once, while the cursor is in Panel's bounds, even if it hovers over my different control-like objects, all within Panel.
TrackMouseEvent seems like it may be the way to go, or at least I'll know where to dig for the default value. (Yet another setting missing from SystemInformation.) Thanks!
|
|
|
|
|
Arun Bhalla wrote:
I'm writing a library of lightweight control-like objects which paint themselves on controls, such as Panel.
Hehe, my team is creating a library of lightweight controls, called Fluid UI Toolkit[^]
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Cool! I look forward to seeing that near completion... as we all know, the Microsoft-provided WinForms library is not so hot.
I guess my library is quite different from yours... mine is more like Visio shape objects rather than things like toolbars.
|
|
|
|
|
Arun Bhalla wrote:
I guess my library is quite different from yours... mine is more like Visio shape objects rather than things like toolbars.
I figured that. Actually, I plan to use mine for document drawing objects, as it will probably lend itself well to that.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
The main reason (or rather, the straw that broke the camel's back) I wrote the library is that Control.Location, etc. didn't inherently support the location on a ScrollableControl relative to AutoScrollPos. Very annoying. There were other issues, though.
|
|
|
|
|
.NET AutoScroll== .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Yeah, and I'm lazy. AutoScroll seems to mostly work, but in a tricky and incomplete way. Oh well!
|
|
|
|
|
I have a multiline textbox and wanted to know if there was any way to limit the characters that are entered to HEX characters ... I wanted to find an easier way than using the || against all the possible characters that I want to accept ...
Thanks
|
|
|
|
|
Add a handler for the KeyPress event of your text box
<br />
private void myHexTextbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)<br />
{<br />
string Allowed = @"0123456789ABCDEFabcdef";
if (Allowed.IndexOf(e.KeyChar)==-1)<br />
{<br />
e.Handled = true;
}<br />
}<br />
|
|
|
|
|
I have a database application that using a form to present records from the database to the user and let them navigate through the records using foward and back buttons. I use a BindingManagerBase object to navigate the records and everything works fine. However, I have some wierdness going on. When I add a new record, the new record should become record 0 (because the DataView is sorted by a column that is left blank when I create a new record) and I should be able to set the form to display that record by doing this after inserting the new record:
<br />
myBindingManger.Position = 0;<br />
Only it doesn't work. The form still displays the data from the record I was looking at when I inserted the new record. However, if I do this:
<br />
myBindingManger.Position = 1;<br />
myBindingManger.Position--;<br />
It works just fine. Can anybody explain to me what's going on here? It's a mystery to me!
|
|
|
|
|
Can anyone tell me what function is used in c# to canonicalizes a URL, which includes converting unsafe characters and spaces into escape sequences?
In Visual c++ exists this function
BOOL InternetCanonicalizeUrl(
LPCTSTR lpszUrl,
LPTSTR lpszBuffer,
LPDWORD lpdwBufferLength,
DWORD dwFlags
);
but i didn't find the correspondent in c#
thank you
|
|
|
|
|
System.Web.HttpServer.UrlEncode() might be what you need.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Uri url = new System.Uri(myString);
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I have logging code that I want to set a global variable for the whole application, something like bool logging = true;
I don't want to have to go to all my classes and set this variable. What is the best way to handle this? Can I set it in the web.config file? If so, how?
Thanks!
|
|
|
|
|
You could use compiler directives:
#if DEBUG
#endif
This has the benefit of being compiled out when you go to release code.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Take a look at the Trace and TraceSwitch classes.
Brian
|
|
|
|
|
One approach is to create a class that handles the logging and keeps track of whether it's enabled or not, like this:
class Log
{
private static bool m_enabled = System.Configuration.ConfigurationSettings.AppSettings["Logging"] == "true";
public static bool Enabled
{
get { return m_enabled; }
}
public static void Error(string message)
{
if (Enabled)
}
public static void Info(string message)
....
}
Then you can call Log.Error, Log.Info, etc. in your code. For more details on how to use web.config, check out MSDN[^].
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
Thanks Alvaro. That is exactly what I was looking for.
I will keep the other suggestions in mind for other things, however.
Cheers.
|
|
|
|
|
Hi guys,
I am trying to create TCP Listener windows services using C# to listen to a local TCP port continuously.
I have written a windows console application which does the job properly but when I convert it to windows services it did not work, as you know definitely I can not use infinity loop on the OnStart method but I want the services to keep listen to synchronous connection by a client and send response when data received.
The senior as following:
I want to listen to a port which I will receive a string 200 characters from a client then send response as acknowledgement.
Your response is highly appreciated.
Regards,
|
|
|
|
|
You will need to create a thread to listen on, its a simple task,
Create a function in your service class which has the listneing socket and the loop in it, eg:
private void ListeningThread(void)<br />
{<br />
TcpListener oListener = new TcpListener();<br />
<br />
_mnThreadCount ++;<br />
<br />
oListener.Listen(nWhateverPortYouWant)<br />
while(!_mbCloseThreads)<br />
{<br />
}<br />
<br />
_mnThreadCount -- ;<br />
}
In OnStart, create your thread
public override OnStart()<br />
{<br />
_mbCloseThreads = false;<br />
_mnThreadCount = 0;<br />
<br />
ThreadStart oThreadStart = new ThreadStart((void)this.ListeningThread);<br />
Thread oThread = new Thread(oThreadStart);<br />
<br />
oThread.Start();<br />
}
and in your OnStop you need to signal the thread to close (_mbCloseThreads) and wait for the threads to shut down (_mnThreadCount)
public override OnStop()<br />
{<br />
_mbCloseThreads = true;<br />
while(_mnThreadCount > 0)<br />
Thread.Sleep(1);<br />
}
Things to remember:
If the thread crashed, always decrement the threadcount, put it in a finally block and that should be ok.
Use Thread.Sleep(1); at the beginning of each continuous loop so it fress up CPU time else your CPU will run at 100%
The code above might not be 100% correct as its strtaight out of my head, but I am sure you will get the general idea of it.
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
Dear James,
Thanks for your replay, I was doing the same way what you have descripted but to make thing exact what you have mentioned please see below code:
the problem is when I start the services and send first stream data it work for the first request and it send proper response but for the second request it did not work I need to stop & start the services then it work for the first request what do you thing the problem???
public void ListeningThread()
{
//Get application Setting information from app.config
strIpAddress = ConfigurationSettings.AppSettings["IPAddress"];
intPort = Int32.Parse(ConfigurationSettings.AppSettings["Port"]);
strConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
IPAddress IpAddress = IPAddress.Parse(strIpAddress);
TcpListener ilListener = new TcpListener(IpAddress,intPort);
//Start listening
ilListener.Start();
_mnThreadCount ++;
LogError("ilListener.Start();");
while ( !_mbCloseThreads)
{
try
{
TcpClient ilSocket = ilListener.AcceptTcpClient();
NetworkStream networkStream = ilSocket.GetStream();
if(networkStream.CanRead)
{
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[165];
networkStream.Read(bytes, 0, 165);
// Returns the data received from the host to the console.
strRecievedData = Encoding.ASCII.GetString(bytes);
}
else
{
//error
}
if ( (int) ilSocket.ReceiveBufferSize >=165)
{
LogError("data size read" + ilSocket.ReceiveBufferSize + strRecievedData );
EnCodeData(strRecievedData);//here I am doing some changeson srtRecievedData
strSendResponse = strResponse;
if(networkStream.CanWrite)
{
Byte[] sendBytes = Encoding.ASCII.GetBytes(strResponse);
networkStream.Write(sendBytes, 0, sendBytes.Length);
}
else
{
// error here
}
LogError("data Sent:" + strSendResponse);
}
}
catch (Exception ex)
{
//
}
}
_mnThreadCount -- ;
ilListener.Stop();
}
protected override void OnStart(string[] args)
{
_mbCloseThreads = false;
_mnThreadCount = 0;
ThreadStart oThreadStart = new ThreadStart(this.ListeningThread);
Thread oThread = new Thread(oThreadStart);
oThread.Start();
LogError("Service Started");
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
_mbCloseThreads = true;
while(_mnThreadCount > 0)
Thread.Sleep(1);
LogError("Service Stopped");
}
I appreciate you immediate response and Thanks in advance.
Regards,
Baqer
|
|
|
|