|
Use BackGroundWorker component so that your piece of code runs in a new thread. Or you can set up a timer to run the code in other thread.
|
|
|
|
|
Hello,
A timer event would seem to me the write place!
Now you have do decite if you whant to run it in the GUI thread or start an other thread for this checking.
A independend thread would have the posibiliy to run it in lower priority which doesn't effect your GUI to much!
If you whant to run it in GUI thread the Forms.Timer is the write one.
If not, use Threading.Timer or Timers.Timer.
Hope it helps!
All the best,
Martin
|
|
|
|
|
Hi all,
I've been looking at the MVP pattern recently, and it impressed me so much that I've converted my ASP.Net application to make extensive use of it. However, I'm wondering about the best way in which to incorporate validation into the pattern.
Formally I was using the Regex validator in the aspx page; clearly, this is was an inflexible approach - and wouldn't be at all feasible as and when I update the application to Silverlight or roll it as a Winforms app. MVP does solve this problem on a page by page basis, however I can't help but think that in terms of the application I've simply moved a problem up a level, rather than solved it.
In my application some areas of validation are common across different pages. For example, a number of pages are required to validate that the user has entered curreny values and not stupid stuff like "Mike is Ace!" etc. Now I can code this directly in the "presentor", but by doing so I prevent the same code being shared throughout the application.
A thought I had was to create an abstract CustomValidator object, and then make each presentor implement an IValidatable interface which could be passed into the concrete CustomValidator. Is this a good approach, or can anyone suggest a better way?
One other thing that is giving me pause for thought is the ASP.Net Session. Without coupling the presentor to the "web", how can I access the session and maintain portability if (when!) I need to convert to other platforms?
Thanks,
Martin.
|
|
|
|
|
I've done this in the past with the Command pattern. Imagine that you have implemented a base command:
public interface IValidatorCommand
{
void Execute();
}
public class ValidationOutcome
{
public bool Passed = true;
public Type FailureType;
public string Reason;
}
public abstract class ValidatorCommand : IValidatorCommand
{
public ValidatorCommand()
{
}
public override ValidationOutcome Execute() {}
}
public class RegexValidatorCommand : ValidatorCommand
{
protected string regex;
protected string text;
protected RegexValidatorCommand(string regex, string text)
{
this.text = text;
this.regex = regex;
}
public static RegexValidatorCommand Validator(string regex, string text)
{
return new RegexValidatorCommand(regex, text);
}
public override ValidationOutcome Execute()
{
ValidationOutcome outcome = new ValidationOutcome();
outcome.Type = this;
if (...)
{
outcome.Reason = "The regex didn't match your input.";
outcome.Passed = false;
}
}
} Then, all you need do in your code is
ValidationOutcome outcome = RegexValidatorCommand.Validator("regex", txtMyTextbox.Text).Execute();
if (outcome.Passed)
{
}
else
{
}
|
|
|
|
|
|
No problem. Glad to help.
|
|
|
|
|
Are you rolling your own MVP or are you using the Web Client Software Factory? I've only just started looking at this approach myself. Anyway, the latest Enterprise Library has a Validation block, which I've also only just started looking at - today in fact.
Kevin
|
|
|
|
|
I am starting to research obsfucation. I have started to look at different products and they all claim to be perfect and better than the others. Can some of you share your experience with any of the products out there. I know that none of them are perfect, but some should be better than none.
Thanks!
Hogan
|
|
|
|
|
They're all absolute crap. Honestly, I haven't found one that always works on our WinForms rich client.
The best I've seen is SmartAssembly and XenoCode. However, they're both crap in that they still fail often, just a lot less than the others.
|
|
|
|
|
Thanks for the reply Judah. After my research today, the two that I thought might fit best are the two you mentioned. SmartAssembly was first on my list. That being said, can you be more specific about them failing often? If you mean that the application breaks while it is running, that is one thing, but if you mean that it breaks the code that is released, then that is a big concern for me.
Thanks a ton for responding!
Hogan
|
|
|
|
|
It breaks the code. More often than not, we'll obfuscate and suddenly our app won't run at all, but will crash upon startup because the obfuscator's IL writing is crap.
Frankly, I feel obfuscation is a big hack that doesn't fit well in the .NET world. It tries to solve a problem that exists only in the minds of paranoid software managers.
|
|
|
|
|
I don't have any experience with them myself, but nearly everything I've heard about them is negative. The general consensus seems to be that if you have a piece of code you'd really like to protect, you have two options:
1. Put it in an unmanaged DLL, then invoke its methods from your managed program. This isn't perfect, but disassembling unmanaged code is less trivial than disassembling managed code.
2. Don't even ship the secure binary. Keep it in a safe location - i.e. on your web server, and have the client make web calls to your service. This is the ideal solution, as you don't have to worry about obfuscation. The client never even has access to your binary! Of course, this solution is only appropriate for a very limited number of scenarios. Your clients need constant network access to make this work.
Good luck!
|
|
|
|
|
Is there a way to draw a rectangle on top of a loaded image that a user can drag to create a selection area? I can make a rectangle and have it follow the mouse movements, but i don't know how to redraw the underlying image to clear the dragging effect. The image in the picturebox is rather large (10000x10000 pix give or take).
Any help or pointers is much appreciated.
R.Myers
|
|
|
|
|
R.Myers wrote: can make a rectangle and have it follow the mouse movements, but i don't know how to redraw the underlying image to clear the dragging effect.
Do you use double buffering? First draw both the image and the rectangle to an offscreen surface and then present it on the screen.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
If you're drawing onto the actual Image in the picturebox (IE through Graphics.FromImage() ) then the actual image is going to be edited and you won't be able to "clear" it without loading the image again (expensive for a huge image like that!).
Instead what you should do is override the OnPaint event of the PictureBox and take its graphic region from the PaintEventArgs (PaintEventArgs.Graphics), and then do your drawing there.
|
|
|
|
|
Thanks PhilDanger & greeeg
I'll take a look into these ideas
R.Myers
|
|
|
|
|
I have a enum.I need to capture this enum in a string array. and also i need to check it with a string parameter that comes from with the function.
function is a boolean.if enum values which is in string array are matches with the string parameter then it will return true or else false.
public bool aaa(string bbb)
{
string []----->capture enum
now string [] will check with the string parameter.
if matches
{
return true;
}
}
|
|
|
|
|
Enum.GetNames(typeof(myEnum))
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
I answered you both times you asked this yesterday, why don't you go read them?!
|
|
|
|
|
does this code goes in public class or i have to create new class and how?
i want to know where to right a code for error handleing please some one give me a answer.
tahank you
-- modified at 13:21 Wednesday 11th July, 2007
|
|
|
|
|
Please either be more explicit in your requirements or read up on try, catch, finally.
If you don't know how to research then use the following link:
Google knows everything![^]
or browse the articles here on CP.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hi,
On MSDN this property looks like:
public static string HashAlgorithmType { get; }
When I try to override it I get an error. My code:
public override string HashAlgorithmType
{
get { return m_HashAlgorithmType; }
}
Error:
Error 81 'My.Web.Security.MyMembershipProvider.HashAlgorithmType': no suitable method found to override
I don't know why I am getting this error. Please can someone advise?
Regards
ma se
|
|
|
|
|
do you see any difference between the following lines ?
public static string HashAlgorithmType
public override string HashAlgorithmType
|
|
|
|
|
Yes there is.
I see my mistake. I was using that property in my custom membership provider class, and there is no such property.
|
|
|
|
|
you should be able to override it statically: public static override string...
en watse naam is daai..?
|
|
|
|