Click here to Skip to main content
       

C#

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
QuestionHOW TO ANSWER A QUESTIONadminChris Maunder12 Jul '09 - 22:36 
Apologies for the shouting but this is important.
 
When answering a question please:
  1. Read the question carefully
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
  3. If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
  4. If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
 
cheers,
Chris Maunder
 
The Code Project Co-founder
Microsoft C++ MVP

QuestionHow to get an answer to your questionadminChris Maunder10 Nov '05 - 16:31 
For those new to message boards please try to follow a few simple rules when posting your question.
  1. Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
     
  2. Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
     
  3. Keep the subject line brief, but descriptive. eg "File Serialization problem"
     
  4. Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
     
  5. Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
     
  6. Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
     
  7. If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
     
  8. Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
     
  9. Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
     
  10. Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
     
  11. If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
     
  12. No advertising or soliciting.
     
  13. We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
 
The Code Project Co-founder
Microsoft C++ MVP

Questionnested switchmemberMKS Khalid12hrs 32mins ago 
how to check arithmetic ,logical, trigonometric and gromatric
values in nested switching ..
i mean how to use nested switch for the above operators
when i press l it us some logical operation \
and when i press a give some arithmetic operation and so on....
AnswerRe: nested switchmvpRichard MacCutchan3hrs 3mins ago 
You are approaching this from the wrong direction. You first need to define your problem and then break it up into the separate parts necessary for a solution. Only then can you decide whether you need any switch statements, let alone nested ones.
Use the best guess

QuestionDifference between Thread, ThreadPool & BackgroundWorker c#memberTridip Bhattacharjee15hrs 45mins ago 
i many time call method with the help of thread like
 
static void Main( string[] args )
{
Thread t = new Thread( MyFunction );
t.Start();
}
 
static void MyFunction()
{
//code goes here
}
 
and some time i use ThreadPool class also like
 
System.Threading.ThreadPool.QueueUserWorkItem(delegate {
MyFunction();
}, null);
 
but i do not understand what is the difference between calling any method with the help of thread class or ThreadPool class
 
so i am looking a good discussion about what is the difference between Thread & ThreadPool class.also need to know when we should use Thread class to call a method and when ThreadPool class to call any method ? if possible discuss also with sample code with sample situation.
 
another very important question is that if i start multiple thread then my application performance will become low or bad ? if yes then tell me why...?
 
now also tell me what is BackgroundWorker class and how it is different from Thread & ThreadPool class. how far i heard that BackgroundWorker class also create a separate thread to run any method. so please discuss how it is different from Thread & ThreadPool class and when one should go for BackgroundWorker class.
 
here is small sample code of BackgroundWorker
 
private void button1_Click(object sender, EventArgs e)
{
BackgroundWorker bw = new BackgroundWorker();
 
// this allows our worker to report progress during work
bw.WorkerReportsProgress = true;
 
// what to do in the background thread
bw.DoWork += new DoWorkEventHandler(
delegate(object o, DoWorkEventArgs args)
{
BackgroundWorker b = o as BackgroundWorker;
 
// do some simple processing for 10 seconds
for (int i = 1; i <= 10; i++)
{
// report the progress in percent
b.ReportProgress(i * 10);
Thread.Sleep(1000);
}
 
});
 
// what to do when progress changed (update the progress bar for example)
bw.ProgressChanged += new ProgressChangedEventHandler(
delegate(object o, ProgressChangedEventArgs args)
{
label1.Text = string.Format("{0}% Completed", args.ProgressPercentage);
});
 
// what to do when worker completes its task (notify the user)
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
delegate(object o, RunWorkerCompletedEventArgs args)
{
label1.Text = "Finished!";
});
 
bw.RunWorkerAsync();
}
tbhattacharjee

AnswerRe: Difference between Thread, ThreadPool & BackgroundWorker c#mvpEddy Vluggen15hrs 28mins ago 
Tridip Bhattacharjee wrote:
with the help of thread class or ThreadPool class

The threadpool holds pre-created threads; those always come in handy when programming UI-tasks to do async processing. They're background-threads, and get recycled to the pool when finished. Background-thread get destroyed automatic when your app closes.
 
If you need something more complex, you'd create your own[^].
 
Tridip Bhattacharjee wrote:
another very important question is that if i start multiple thread then my application performance will become low or bad ?

It doesn't make execution "faster", it creates a new execution-path, one that "might" run on a different CPU (if you have multiple). You'll already need them if you want a nice responsive UI.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

QuestionMinidumps.memberPHS24116hrs 11mins ago 
I've created a small VS 2012 c# project that eventually does a divide-by-zero. I catch the exception and then do a call to MiniDumpWriteDump and it successfully creates a dump file.
 
Obviously I have the pdb and source files.
 
What I'd like to do now is load the minidump into VS and then examine it so I can get familiar with how to read it etc. As I understand, the minidump file should be able to display exactly what was going on and using the debugger, I could look at the stack trace and display variables? Double-clicking the minidump file opens it in VS 2012 but I'm really left with the puzzle, what now? Has anyone loaded a dump file before and looked at it in VS?
 
I've searched for answers but the term minidump is so ubiquitous that it's really not easy to what's relevant to VS and what isn't. I'm led to believe that if I have the dump file and the pdb files and the source then I should be able to see an exact snapshot of went turned tits-up. I just don't really know what's the best way to load it and change any settings to use it. If I can get it working on a simple divide-by-zero app then I can use them in our production app which'll help us deal with fatal problems reported by our users.
 
TIA.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

AnswerRe: Minidumps.mvpEddy Vluggen15hrs 35mins ago 
PHS241 wrote:
Double-clicking the minidump file opens it in VS 2012 but I'm really left with the puzzle, what now?

Now you set the location of the debug-symbols. I got it working using VS2010 and .NET 4, so you should be able to achieve the same.
 
I followed this[^] tutorial.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: Minidumps.memberPHS24115hrs 5mins ago 
Thanks Eddy. I had a quick squizz at the link and I've bookmarked it and I'll read it later on.Thumbs Up | :thumbsup:
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

QuestionSome Basic Help About A Modification In a Script!memberJesús Frías18hrs 2mins ago 
I have a simple question but for someone like me who is not familiar with c# is giving a bit of trouble. I am making a basic script in c# for a bot in a videogame (TERA). What I want is to avoid attacking static immortal debuffs when my character approaches to them. A simple script without nothing would be like this:
 
//Blank.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
 
namespace SimpleCombat
{
 
public class EntryPoint : ZurasBot.Addons.ICombat
{
 
public override string Name
{
get
{
return "Shell";
}
}
 

public override void OnLoad()
{
}
 
public override void OnUnload()
{
}
 
public override void Settings()
{
}
 
public override void OnBotStart()
{
}
 
public override void OnBotStop()
{
}
 
public override void Patrolling()
{
} //end Patrolling

public override Boolean Pull(MyTERA.Helpers.ObjectManager.TERAObject Object)
{
return true;
} //end Pull

public override Boolean Combat(MyTERA.Helpers.ObjectManager.TERAObject Object)
{
return true;
} //end Combat

public override void PostCombat()
{
}
 
} //end EntryPoint

} //end SimpleCombat
 

The question is: How/where do I declare/define the pullfunction? What I have to add is this:
 
if (Object.S1NPCDataController.Name == "name1") return false;
 
"name1" being the name of the static immortal debuff. Anyone could help me? It is important to me since I am helping a friend to level up his character so he can play with the rest of us! I would really appreciate any help you could give me, it would mean a lot to me! Thank you very much for your help, I hope I can find a solution! Have a nice weekend! Smile | :)
AnswerRe: Some Basic Help About A Modification In a Script!mvpDave Kreskowiak16hrs 26mins ago 
You'd be better off asking in the forums for the game. You're question has everything to do with the SDK for the game, not C#.
 
It's VERY unlikely any of the regulars here have written anything for that game.

AnswerRe: Some Basic Help About A Modification In a Script!professionalCalvijn13hrs 24mins ago 
Well I don't know the scripting for the game. But if that what you posted is the default BotScript than I would say it should be placed in the "Pull" or "Combat" Method.
 
ex.:
public override Boolean Pull(MyTERA.Helpers.ObjectManager.TERAObject Object)
{
    if(Object != null && Object.S1NPCDataController != null)
        return Object.S1NPCDataController.Name != "name1";
    
    return true;
 
} //end Combat

Questionc@#memberMKS Khalid18hrs 23mins ago 
how use nested switch in c#
AnswerRe: c@#protectorOriginalGriff18hrs 19mins ago 
            int value1 = 2;
            int value2 = 6;
            switch (value1)
                {
                case 1: break;
                case 2:
                    switch (value2)
                        {
                        case 1: break;
                        case 2: break;
                        default: throw new ApplicationException("Unknown value: Value2=" + value2);
                        }
                    break;
                default: throw new ApplicationException("Unknown value: Value1=" + value1);
                }
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

Questionc# Thumbnail ViewermemberMember 873647517 May '13 - 18:39 
Hello,
 
I am beginner ( Noob ) in c#,
I am trying to make a small Asset browsing tool for myself, I just wanted to be sure if the way i am going is good or is there a better way to do it.
 
Currently I have 4 classes
ThumbViewer : extends FlowlayoutPanel
ThumbItem : extends Button
CacheManager.
 
I have overridden the paint method in the ThumbItem class and painting my Own way.
 
I also have a Background worker process which reads image file and gets thumbnail out if it and then assigns it to the Image property in the Button.
 

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.ComponentModel;
using System.Drawing.Imaging;
 
namespace Thumbnailer
{
    public class ThumbItem : Button
    {
        private BackgroundWorker bw;
        private string _fullfilename;
        private bool _ismouseover = false;
        private bool _isSelected = false;
        private const int THUMBNAIL_DATA = 0x501B;
        private ToolTip _btn_Tooltip;
        private bool isDisposed = false;
        private bool _itemvisiblecalled = false;
        private bool _itemnotvisiblecalled = false;
 
        #region Properties
        public string FullName
        {
            get { return _fullfilename; }
            set { _fullfilename = value; }
        }        
        public bool Selected
        {
            get { return _isSelected; }
            set { _isSelected = value; }
        }
        public Image FileIcon { get; private set; }
        public bool isVisible { get; set; }
        public string FileName { get; set; }
        #endregion        
 
        #region Constructor
        public ThumbItem()
        {           
            //Setthe Items properties
            this.Text = "PlaceHolder Thumb";
            this.Size = new Size(128, 144);
            this.Padding = new Padding(4);            
            this.BackColor = Color.Transparent;            
            this.Font = new Font("Verdana", 9, GraphicsUnit.Point);
            this.DoubleBuffered = true;
 
            //Set the background worker and its Handlers
            bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.WorkerSupportsCancellation = true;
            bw.DoWork += new DoWorkEventHandler(BW_DoWork);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BW_RunWorkerCompleted);           
        }
 
        public ThumbItem(string file)
            : this()
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException("Specified file " + file + " doesnt exists.");
            }
            FileInfo fi = new FileInfo(file);
            this.Text = fi.Name.Replace(fi.Extension, "");
            this.FileName = fi.Name.Replace(fi.Extension, "");
            this.FullName = fi.FullName;                        
            bw.RunWorkerAsync();
        }
 
        ~ThumbItem()
        {
            if(!this.isDisposed)
            {
                bw.DoWork -= BW_DoWork;
                bw.RunWorkerCompleted -= BW_RunWorkerCompleted;
                this.bw.Dispose();
            }
        }
        #endregion        
 
        #region Background Worker
        private void BW_DoWork(object sender, DoWorkEventArgs e)
        {
            if (this._fullfilename != "")
            {                
                Image _thumbimg = null;
                Image _icon = null;
                FileInfo fi = new FileInfo(this._fullfilename);                
                if(fi.Extension == ".JPG")
                {
                    using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(this._fullfilename)))
                    {
                        using (Image img = Image.FromStream(ms))
                        {
                            if (CacheManager<Image>.CurrentInstance.isExists(this.FullName))
                            {
                                _thumbimg = CacheManager<Image>.CurrentInstance.GetByKey(this.FullName);
                            }
                            else
                            {
                                if (img != null)
                                {
                                    _thumbimg = img.GetThumbnailImage(64, 64, abort_callback, IntPtr.Zero);                                    
                                    CacheManager<Image>.CurrentInstance.Add(this.FullName, _thumbimg);
                                }
                            }
                        }                        
                    }
                }
                else
                {
                    _icon = Icon.ExtractAssociatedIcon(this.FullName).ToBitmap();
                }
                e.Result = new Image[] { _thumbimg, _icon };                
            }
        }
        private void BW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {            
            this.Image = ((Image[])e.Result)[0];
            this.FileIcon = ((Image[])e.Result)[1];
            this.Invalidate();
        }
        #endregion       
 
        #region Painting Methods
        protected override void OnPaint(PaintEventArgs pevent)
        {                 
            //base.OnPaint(pevent);
            Graphics gfx = pevent.Graphics;
 
            StringFormat formatter = new StringFormat();
            formatter.LineAlignment = StringAlignment.Center;
            formatter.Alignment = StringAlignment.Center;
            Rectangle textrect = new Rectangle(0, (this.Height / 2) - (this.FontHeight / 2) - this.Padding.All, this.Width, this.Height);
                           
            Color fontcolor = Color.White;
            Rectangle parentbounds = this.Parent.Bounds;
 
            //Clear the Control Background with ts Parent Background COlor
            if (this.Parent != null)
            {
                gfx.Clear(this.Parent.BackColor);
            }
 
            if (((this.Bounds.Bottom - 10) < this.Parent.Bounds.Top) || (this.Bounds.Top - 10) > this.Parent.Bounds.Bottom)
            {
                if(!this._itemnotvisiblecalled)
                {
                    ItemNotVisible();
                }
            }
            else
            {
                if(!this._itemvisiblecalled)
                {
                    ItemVisible();
                }
            }           
 
            if(this.FileName == "IMG_0035")
            {
                Console.WriteLine("TEmp");
            }
 
            //If the Item is Selected the Colorize the Font to show Selection
            if (this.Selected)
            {
                gfx.FillRectangle(new LinearGradientBrush(this.ClientRectangle, Color.FromArgb(25, 255, 255, 255), Color.FromArgb(150, 255, 255, 255), LinearGradientMode.Vertical), this.ClientRectangle);
            }
 
            //onMOuseHover Effects
            if (this._ismouseover)
            {
                gfx.FillRectangle(new LinearGradientBrush(this.ClientRectangle, Color.FromArgb(25, 255, 255, 255), Color.FromArgb(100, 255, 255, 255), LinearGradientMode.Vertical), this.ClientRectangle);
            }
 
            //Draw the Broder
            Rectangle borderrect = this.ClientRectangle;
            ControlPaint.DrawBorder(gfx, borderrect, Color.FromArgb(100, 255, 255, 255), ButtonBorderStyle.Solid);
 
            //If the Image is Specified then Add that Image to Control            
            if (this.Image != null)
            {
                Rectangle imgrect = new Rectangle(this.Padding.All, this.Padding.All, (this.Width - (this.Padding.All * 2)), (this.Width - (this.Padding.All * 2)));
                gfx.DrawImage(this.Image, imgrect);
            }
            //Else Check if the Icon is Specified, if yes then Paint the Icon
            else if (this.FileIcon != null)
            {
                Rectangle iconrect = new Rectangle(((this.Width / 2) - 16), ((this.Height / 2) - 16), 32, 32);
                gfx.DrawImage(this.FileIcon, iconrect);
            }
 
            //Draw the Text on the Control
            string temp = this.Text;
            SizeF textsize = gfx.MeasureString(temp, this.Font);
            while (textsize.Width > this.Width / 1.5)
            {
                temp = temp.Remove(temp.Length - 1);
                textsize = gfx.MeasureString(temp, this.Font);
            }
            temp += "....";
            gfx.DrawString(temp, this.Font, new SolidBrush(fontcolor), textrect, formatter);        
        }
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);            
        }
        #endregion
 
        #region Helper Methods
        public static Image ResizeImage(Image imgToResize, Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;
 
            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;
 
            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);
 
            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;
 
            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);
 
            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.Low;
 
            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();
 
            return (Image)b;
        }
        public void RefreshThumbnail()
        {
            this.Image = null;            
            while(!this.bw.IsBusy)
            {
                this.bw.RunWorkerAsync();
            }
        }
        private void ItemVisible()
        {
            this._itemvisiblecalled = true;
            this._itemnotvisiblecalled = false;
            //RefreshThumbnail();
        }
        private void ItemNotVisible()
        {            
            //this.Image = null;
            this._itemvisiblecalled = false;
            this._itemnotvisiblecalled = true;
        }
        private static bool HasJpegHeader(string filename)
        {
            using (BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)))
            {
                UInt16 soi = br.ReadUInt16();  // Start of Image (SOI) marker (FFD8)
                UInt16 jfif = br.ReadUInt16(); // JFIF marker (FFE0)

                return soi == 0xd8ff && jfif == 0xe0ff;
            }
        }
        #endregion
 
        #region Event Handlers
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            this._ismouseover = true;
            if ( _btn_Tooltip == null)
            {
                _btn_Tooltip = new ToolTip();
                FileInfo fi = new FileInfo(this.FullName);
 
                string tooltiptext = "";
                tooltiptext += "FileName : "+fi.Name+"\n";
                tooltiptext += "Path : "+fi.FullName+"\n";
                tooltiptext += "Directory : " + fi.DirectoryName + "\n";
                _btn_Tooltip.SetToolTip(this, tooltiptext);
            }
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            this._ismouseover = false;
        }
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
        }        
        #endregion        
 
        #region Event Methods
        #endregion
 
        #region UnUsed Methods
        private bool abort_callback()
        {
            return false;
        }
        #endregion
 
        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.ResumeLayout(false);
 
        }
    }
}
 
Can anyone please tell me if this is the best way to do it, if not then can you please guide me in right direction.
 
Thanks
Dinesh
AnswerRe: c# Thumbnail ViewermemberBillWoodruff17 May '13 - 20:42 
Hi Dinesh,
 
If you are a "newbie," then, you are at the top of your class: this is a very advanced example using BackgroundWorker, custom Painting, sub-classed WinForms native Controls, etc.
 
The advanced nature of your code, and the relative lack of comments, or commented-out code, makes me wonder if you wrote this yourself (that's not an accusation !), or if you modified an existing example.
 
What specific questions, or concerns, do you have about your code ? What happens now, using your code, when you run it, and browse many pictures ? Is the application fast enough under full load to satisfy you ?
 
The only thing I wonder is: why did you choose to use a Control that inherits from Button, rather than a PictureBox.
 
It would be interesting to see your CacheManager code, or at least to have a brief description of how you implemented that.
 
Personally, I have found using the WinForms FlowLayoutPanel very tricky.
 
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis

GeneralRe: c# Thumbnail ViewermemberMember 873647518hrs 35mins ago 
Hello Bill,
 
First of all thank you for your quick answer I wasn't expecting it, I have never ever got any answer from forums.
 
Yes everything is not born out of my brain, I took the basic idea and inspiration from
HERE
 
Using the Background worker is an idea, that I got idea while searching for ways to load images in async way.
 
Cache Manager concept was cleared by one of my cousin and I wrote my onw. but later on I fond one which was more better so used it.
 
And that's how I compiled all this, and that is the only reason I am not confident that what i did is right Confused | :confused:
 
Is the application fast enough under full load to satisfy you ?
No I am not.
Currently I tried loading 200 Images (each Image of around 6 MB) It takes around 1 Sec to Populate all the items in the Panel, and then around 10-15 secs to display all the Images on the items.
I was expecting it to do everything in less then sec, Am I expecting too much.
 
What specific questions, or concerns, do you have about your code ?
I wanted to know if there are any optimizations that I can do and I missed,
Also Since I am a newbie I am not pretty sure if I have done everything in correct way.
 
So as of now these are small questions I have.
 
Thanks
GeneralRe: c# Thumbnail ViewermvpDave Kreskowiak16hrs 33mins ago 
Member 8736475 wrote:
Currently I tried loading 200 Images (each Image of around 6 MB) It takes around
1 Sec to Populate all the items in the Panel, and then around 10-15 secs to
display all the Images on the items.
I was expecting it to do everything in
less then sec, Am I expecting too much.

 
So you want your HD to come up with 1.2GB worth of data in less than a second? Yeah, you're expecting too much, WAY too much.
 
To get the illusion of speed you have to cheat a bit. You load only the images you are displaying. If you're got 200 images in a folder, but can only show 10 on screen at a time, you only load the 10 that need to be loaded. The others can wait until either the user scrolls to see them or you can farm those off to a background thread to load.

QuestionFlashing formmemberPozzaVecia17 May '13 - 12:28 
Is there a way to make a Form flashing in c#.
 
First idea is to use a timer changing form color. Is there a more elegant way?
 
Thanks for your time
AnswerRe: Flashing formmvpDave Kreskowiak17 May '13 - 17:34 
Why not just call FlashWindowEx[^]?

AnswerRe: Flashing form [modified]memberBillWoodruff17 May '13 - 20:17 
Hi, PozzaVecia,
 
There are two main reasons you might want to make a Form/Window flash: one is to indicate an error message, or something urgently requiring the user's attention. In that case you want to bring the Form to the front, to make sure it's visible. The usual practice, in that case, is to put up a modal Form/Window, which will automatically appear as the frontmost window, and block your application.
 
You can define a Form, with whatever you want on it, and use FormX.ShowDialog() to display it modally. In many cases, however, the built-in MessageBox facility is all you need to use. Both these objects will automatically become the frontmost window when they are shown.
 
The second case is when you want to indicate to the end-user that you want them to bring a Form to the front, that's not in front now. But, it's hard for me to see a real reason for doing that:
 
1. if the Window is covered over by other Windows, the user won't see it change color, or Flash.
 
Using FlashWindowEx will not make the Window the active window, and bring it frontmost, although the Window will appear to have changed status visually, from inactive to active. MSDN docs for 'FlashWindowEx:
 
"It does not change the active state of the window."
 
"When a window flashes, it appears to change from inactive to active status. An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar."
 
In summary:
 
1. yes, you can make a Window flash, either by using the FlashWindowEx api that Dave K. referred you to, or by writing code, as you mentioned, using a Timer.
 
2. imho, you should use a modal Form/Window whenever you absolutely must get the end-user's attention, are willing to block the application, and require a response from the user.
 
3. in most cases, the built-in modal MessageBox facility will give you, for "free," a choice of buttons, default action button, icon, etc.
DialogResult result = MessageBox.Show("Core Melt Down Imminent" ,"Chernobyl Emergency Alert !",MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button3);
 
switch (result.ToString())
{
    case "Ignore":
        MessageBox.Show("Ignorance is life as usual.");
        break;
    case "Abort":
        MessageBox.Show("To abort is impossible, sorry.");
        break;
    case "Retry":
        MessageBox.Show("Trying again is a waste of time.");
        break;
}
There are some articles here on CP that may be useful to you: [^].
 
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis


modified 20 hrs ago.

GeneralRe: Flashing formmemberPozzaVecia17 May '13 - 22:01 
very very useful!!!
thanks a lot
QuestionTimestamp Value in SQLServermemberabhi_here17 May '13 - 8:13 
How can I read a the value of a column datatype Timestamp in my c# code?
 
I know that the timestamp is not a datetime in sql server.
I just want to read this to a byte array.
 
My code so far:
I have tried 3 variations and none of them even compile.
 
//does not compile 
var myTimestamp = (byte)dr["TimeStamp"].ToString();
//does not compile
var myTimestamp = dr["TimeStamp"].ToString() as byte[];
//does not compile
var myTimestamp = dr["TimeStamp"].ToString();
 
I have googled and am unable to find it.
Pendin Approval

AnswerRe: Timestamp Value in SQLServerprofessionalPIEBALDconsult17 May '13 - 8:43 
Maybe try System.Byte[] myTimestamp = (System.Byte[]) dr["TimeStamp"] ;
AnswerRe: Timestamp Value in SQLServermemberjschell17 May '13 - 10:32 
Try reading it as a long.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 19 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid