|
|
I have this code for autocomplete:
foreach(string match in myList){
if( !string.IsNullOrEmpty(text_box1) ){
if( match.StartsWith(text_box1.ToString(),
StringComparison.CurrentCultureIgnoreCase) ){
MessageBox.Show(match);
}
}
}
In String "The follow me", case find "the", the string is show me. But case find "follow" or "Follow", is not show. I'm tried with Contains but not solved. What can i do ?
|
|
|
|
|
You are using StartsWith . If you look for "The follow", you will find the string output.
What did you try with Contains ?
|
|
|
|
|
With Contains, when find "follow" is show the complete string. But i try with "the fol" no show more, and "the Follow", example, to not show.
|
|
|
|
|
|
Solved the problem with "||":
if( match.StartsWith(text_box1.ToString(),
StringComparison.CurrentCultureIgnoreCase) || match.Contains(text_box1) )
Tanks for all help
|
|
|
|
|
I'm writing some DLL's and have a question.
If I throw the exception in the catch block does the finally ever execute? Reason why I am doing this is because the DLL's do not perform logging, the calling class does. But I need to make sure I dispose of my objects.
Example:
SqlConnection conn = null;
SqlCommand cmd = null;
try
{
}
catch (Exception ex)
{
throw;
}
finally
{
if (cmd != null)
cmd.Dispose();
if (conn != null)
conn.Dispose();
}
IS that proper or should I dispose in the catch block AND the finally block because the finally will never execute since i'm rethrowing the exception?
|
|
|
|
|
The finally block will almost always execute - let all dispose methods remain in the finally block.
|
|
|
|
|
Thanks! That is what I needed to know! Just wasn't 100% if the finally would execute because I threw the error again in the catch block.
|
|
|
|
|
Yes.... code in finally block will always execute unconditionally (unless you shut down the PC by pulling the power cord ...)
|
|
|
|
|
JD86 wrote: make sure I dispose of my objects In such a case, I prefer a using statement:
using (IDbConnection conn = ...)
{
using (IDbCommand cmd = ...)
{
}
}
Rhe Dispose method of the object will be called when the using block is left - regardless of the reason for leaving.
|
|
|
|
|
I don't really like the using method. No way to really catch errors unless you do another try, catch within the using statement and then that is just redundant.
I just stick to try, catch, finally and dispose of everything myself.
|
|
|
|
|
So use finally, it will do exactly you want. Just to reinforce, yes, it runs all the time, in good or bad cases (exceptions).
|
|
|
|
|
I have an application which I wrote and I also maintain in my facility. Occasionally I add new features based on management's needs. I have the application setup with a Click-Once deployment. Typically I publish the application to a local server. However, my system is on a wireless connection and for some reason the internal network disappears from my list occasionally, so now I can't connect to publish updates directly (second time this has happened). I know that I can publish locally and click "Updates..." to change the update location if it's different from the publish path. Well, how can I publish to my local system but copy it to the server's publish location via USB flash drive? I mean, do I simply copy/paste the content from the local publish folder to the separate (server) location I specify for updates?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
If you are deploying your click once to a separate server, you need to use Mage (or MageUI) to update the deployed application. There are all sorts of security items in the deployment that need to be updated, and these tools do all the heavy work for you. You can find a simple step by step guide here[^].
|
|
|
|
|
Thank you, I'll read the article today and see where I can get with it.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
I was testing the garbage collection in C#, and came across something that doesn't make sense to me. I know about Garbage Collection happening "randomly", but I am using GC.Collect() here. Please see code below and then the result information:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Method();
Method2();
}
void Method()
{
TestA b = new TestA("first one");
for (int i = 0; i < 10; i++)
{
TestA a = new TestA();
}
GC.Collect();
}
void Method2()
{
}
}
public class TestA
{
string MSG;
public TestA()
{
MSG = "Not first one";
}
public TestA(string msg)
{
MSG = msg;
}
~TestA()
{
MessageBox.Show("Destructing A " + MSG);
}
}
I am getting "Not first one" (destructor and I am assuming GC'ed) 9 times. Then when I close the form I am getting "first one" 1 time and then "Not first one" 1 more time.
My main question is why isn't instance b of TestA being collected on GC.Collect? Are the ones in the for loop falling out of scope, but not the one before my for loop? If so, please explain what is keeping it in scope as Method() has completed.
Thank you.
Respectfully,
D
|
|
|
|
|
DSLoginYea wrote: My main question is why isn't instance b of TestA being collected on GC.Collect? It's no longer in scope, but that doesn't guarantee that it'll be collected.
If you want to know more about Garbage Collection, there's a lot of documentation[^] on it, including it's inner workings and the reasoning on the design-decisions.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Calling GC.Collect() does not mean the GC will run instantly.
Its only an indication that the GC can be run.
|
|
|
|
|
Add a GC.WaitForPendingFinalizers() after GC.Collect() - then the results may come closer to what you expected.
|
|
|
|
|
Hi All,
I am trying to run an existing project by using the F5 option. since this project is set up as a service, it keeps erroring out with message, "Cannot start service from command line or debugger. A windows service must first be installed then started with Server Explorer, windows services admin tool or NET Start Command".
I did google this but comes back with a lot of results. Did someone go through, and if so can you please let me know how you resolved it?
I am new to the windows service in ASP.Net.
Thanks so much.
|
|
|
|
|
|
I do something like the following. Basically you need to have a windows form or WPF app ready to run. You can do this by just adding one to your project. You comment the service and uncomment the forms code to run in VS. Put it back to run as a service. If this isn't already set for you then you have some work to do to make it run, but it shouldn't be hard. This code is in the Program.cs file
static class Program
{
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new myNewService() };
ServiceBase.Run(ServicesToRun);
}
}
|
|
|
|
|
|
Hi Team,
Below i faces issues in String using RichText box control
for example :
Hi Welcome website like www.google.com and visit this site lot of things
when i bind this strings in our RichText box control , unable mid word like hyberlink (www.google.com)
please give your suggestion and needful
thanks
senthil
|
|
|
|