|
Dalek Dave's a tool? You could well be right.
|
|
|
|
|
No, not even then.
And, no there are not.
|
|
|
|
|
Pete O'Hanlon wrote: the regex for this is:
^(\d*(0){4})
Send this in to Alex Trebeck for use on Jeopardy, and we'll all guess what the question was.
"I'll take code fragments for a thousand, Alex."
|
|
|
|
|
Hallo,
there is a List which has to be filled with Strings when the program starts up. I am missing the common practice in such cases, if there is any at all.
I am thinking of putting all strings names in a text file from where the programme should read and fill up the List. That way, I will always be able to change it, by adding more names, changing or deleting them, avoiding the risk to mess up with the code.
Are there any better suggestions on that?
Would that be too slow if the List came at thousands of names?
Should it be better to have a binary list of text strings, if something like that would be possible (through serialization maybe?)
Those are some of the questions coming up, when I am thinking of the appropriate solution to the problem.
Thanks.
|
|
|
|
|
I would go with strings in a file, then just
List<string> myList = new List<string>();
myList.AddRange(File.ReadAllLines(path)); The memory space shouldn't be a problem, even with thousands of strings, and it won't take long to load anyway. You could hold them as XML data, but then it is a bit harder to edit: you can cause errors in the file. At least with straight text, you don't need any special tools (or intelligence) to change them, so that job can be hived off to the office idiot junior.
A quick test said mine read 5000 lines in 7mSec (on the first try, so caching was not involved) - and my PC is nowhere near SOTA!
Always go with an option that means you don't have to re-compile!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Thanks for replying. What about having the text list in another form? Is there a way to compile it? Does this go under the serialization chapter?
|
|
|
|
|
Griff gave a good answer, but I wonder at the wisdom of using a List rather than a database.
Could you give more information on what you are trying to do?
|
|
|
|
|
I want it to be a simple metric conversion programme, such as foot to meter and so on. My purpose is mainly an exercise for myself, but also to be able to share it with friends on a simple download. I cannot ask them to have a database already installed into their system, they wouldn't know how to do that.
modified on Thursday, April 7, 2011 11:26 AM
|
|
|
|
|
Asnwering your comment to PIEBALDconsult and to me at teh same time: Not all databases need any installation. For example, there is SqlCE which was meant for Windows Mobile devices, but can be used by desktop machines. The code is built into .NET, so if they can run your program, it can use a database. It's pretty full SQL with only a few limitations: single user, no stored procedures, no triggers, but for 90% of simple apps it works like a charm - Outlook stores it's data in modified SqlCE databases.
You can serialize it, yes:
string path = @"F:\Temp\roman.txt";
List<string> myList = new List<string>();
myList.AddRange(File.ReadAllLines(path));
using (Stream stream = File.Open(@"F:\Temp\data.bin", FileMode.Create))
{
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, myList);
}
List<string> myList2;
using (Stream stream = File.Open(@"F:\Temp\data.bin", FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
myList2 = (List<string>) bin.Deserialize(stream);
}
But this will be slower than reading text! (Simple tests say about twice as slow!)
Additionally, you will need some utility or method to modify values.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Thanks again for your answer and the nice piece of code.
|
|
|
|
|
Oh, one of those -- an excellent exercise.
According to the file date, I wrote the following last October (probably in response to a post here):
namespace PIEBALD.Lib.LibExt.Convert
{
public interface IConvert
{
double Convert ( double Value ) ;
}
public enum Language
{
CSharp
,
VisualBasic
}
[System.AttributeUsageAttribute(System.AttributeTargets.Field , AllowMultiple=false , Inherited=false)]
public sealed class ConverterAttribute : System.Attribute
{
public ConverterAttribute
(
string Function
,
Language Language
)
{
this.Function = Function ;
this.Language = Language ;
return ;
}
public string Function { get ; private set ; }
public Language Language { get ; private set ; }
}
public enum Conversion
{
[ConverterAttribute("Value * 2.54",Language.VisualBasic)]
FromInchToCentimeter
,
[ConverterAttribute("Value / 2.54",Language.VisualBasic)]
FromCentimeterToInch
,
[ConverterAttribute("( Value - 32.0 ) * 5.0 / 9.0",Language.CSharp)]
FromFahrenheitToCelsius
,
[ConverterAttribute("Value * 9.0 / 5.0 + 32.0",Language.CSharp)]
FromCelsiusToFahrenheit
}
public static class LibExt
{
private static readonly System.Collections.Generic.Dictionary<Conversion,IConvert> conversion ;
static LibExt
(
)
{
conversion = new System.Collections.Generic.Dictionary<Conversion,IConvert>() ;
return ;
}
private static void
Add
(
Conversion Conversion
)
{
System.Reflection.FieldInfo fi = typeof(Conversion).GetField
(
Conversion.ToString()
,
System.Reflection.BindingFlags.Public
|
System.Reflection.BindingFlags.Static
) ;
foreach
(
ConverterAttribute att
in
fi.GetCustomAttributes ( typeof(ConverterAttribute) , false )
)
{
string code = null ;
switch ( att.Language )
{
case Language.CSharp :
{
code = System.String.Format
(
@"
namespace Converter
{{
public class Converter : PIEBALD.Lib.LibExt.Convert.IConvert
{{
public double
Convert
(
double Value
)
{{
return ( {0} ) ;
}}
}}
}}
"
,
att.Function
) ;
break ;
}
case Language.VisualBasic :
{
code = System.String.Format
(
@"
namespace Converter
public class Converter
implements PIEBALD.Lib.LibExt.Convert.IConvert
public function Convert ( byval Value as double ) as double _
implements PIEBALD.Lib.LibExt.Convert.IConvert.Convert
return ( {0} )
end function
end class
end namespace
"
,
att.Function
) ;
break ;
}
}
System.Reflection.Assembly assm = PIEBALD.Lib.LibSys.Compile
(
code
,
att.Language.ToString()
,
System.Reflection.Assembly.GetExecutingAssembly().Location
) ;
conversion [ (Conversion) fi.GetValue ( null ) ] =
(IConvert) assm.CreateInstance ( "Converter.Converter" ) ;
}
return ;
}
public static double
Convert
(
this double Value
,
Conversion Conversion
)
{
if ( !conversion.ContainsKey ( Conversion ) )
{
Add ( Conversion ) ;
}
return ( conversion [ Conversion ].Convert ( Value ) ) ;
}
}
}
Obviously it's not extensible they way you want, but it may give you some ideas.
You should also look at this[^].
May the force be with you.
|
|
|
|
|
Hi, I can currently kill any process by looping through them. I also want to be able to kill hidden processes but no success even though I googled it. As you may guess, the programs that I want to kill don't show up in the task manager nor in GetProcesses(). Have any idea about how to solve?
|
|
|
|
|
AFAIK there are no hidden processes; assuming you clicked the "show processes from all users" button or checkbox, TaskManager shows all of them. You may be unable to get information or kill some of them though, as processes that aren't yours are protected from your prying eyes.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Good answer, gets my vote.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Thanks Rajesh.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
That's not 100% accurate mate. You can get hidden processes, but they take some real effort to develop. Typical examples of hidden processes are rootkits where the rootkit is right down at the kernel level and can intercept process list requests.
|
|
|
|
|
I admit one can do such things, however I do avoid the R word, and didn't want to venture into that direction at all.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I've just ventured there with Rajesh because I feel that bald statements about hidden processes can be dangerous and can lead to misconceptions about the power of task manager.
|
|
|
|
|
Stop Rajesh making bald statements? I wish you good luck.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
Wow.....it's a good article BAB
|
|
|
|
|
You can kill MOST processes, not ANY process. If you're a normal user, you can only kill processes that your account launched. Even as an Admin, you cannot kill processes running under SYSTEM, nor any process above an Admin account.
|
|
|
|
|
It's very simple:
if(!isSystemCriticalProcess && userUnderWhichYourAppRunsHasRights){
showProcess = true;
canKill = true;
}
|
|
|
|
|
d@nish wrote: if(!isSystemCriticalProcess && userUnderWhichYourAppRunsHasRights){ showProcess = true; canKill = true; }
Thanks. I looked for what you gave me but couldn't find the showProcess and cankill properties. Could you be more specific?
|
|
|
|
|
Sorry, I was merely stating that you can see and kill a process only if it is not a system critical process and the user under whose credentials the application runs has the rights.
|
|
|
|
|