|
Use a Singleton-like approach. Make the constructor private and add a static method. In this method return a new instance of the class when a static counter is less than 3 (starting with 0). Then increment the counter.
If the counter is >2 do what ever you like to do if the third instance is delivered.
Small example:
<br />
public class MyRestrictedClass<br />
{<br />
private static int instanceCounter = 0;<br />
private MyRestrictedClass()<br />
{<br />
}<br />
<br />
public MyRestrictedClass GetNextInstance()<br />
{<br />
if(instanceCounter<=2)<br />
{<br />
instanceCounter++;<br />
return new MyRestrictedClass();<br />
}<br />
throw new Exception("Maximum number of instances exceeded.");<br />
}<br />
}<br />
Best regards
Jens
When in trouble,
when in doubt,
run in circles,
scream and shout
modified on Thursday, May 27, 2010 3:18 AM
|
|
|
|
|
thank u Jens,, i m facing another problem in Socket programing in Vb.Net, i had developed a Server which recieve data from clients and forward to others, it was a multi threading application but now it stuck up , it was developed using a VB Winsock wrapper, now i want to develop it using .Net sockets, can u help me in this
|
|
|
|
|
Hi all,
In my application I am creating a word document using a default template doc and later adding dynamic content, this is working fine. My problem is now i am askd to create multiple copies of the same document as single document, for example in my word document i have one page with some content, based on the number of copies, the same page should be repeated in the same document and as single document (strictly as single document only, i tried by creating multiple documents and finally merging all the doc as single, this solution was rejected). To say when we take print out, we specify number of copies, so that we get that number of hard copies, i want the same logic. Binarywriter/streamwriter is not helping me, because my document contains images, please help me to solve this. Give me some URL or samples.
Kindly execuse if i am not clear in my point.
Thanks in advance.
Know is Drop, Unknown is Ocean
|
|
|
|
|
Exelioindia wrote: Give me some URL or samples.
A sample on manipulating Word using C# can be found here[^]. You can find the Microsoft Word Developer Center here[^].
I are Troll
|
|
|
|
|
hi everyone,
I want to change look of controls of window forms for .net framework.
Please suggest me , is there any dll file or any other open source tools that can change look of controls...
Thanx in advance..
|
|
|
|
|
Yep. Rewrite them and render them yourself. Or, use WPF to write your own controls. Or, buy a third party control library where they've done this for you. Or, you have to use themes at the system level to change the look of the controls, but probably not as nicely as a third party library.
|
|
|
|
|
Thanx for reply.PLease can u tell me which third party library I should use. Or can u give me some third party libraries list.
Thanx
|
|
|
|
|
Have a look at the code here to see what you would need to write just to customize the borders of a form.
My signature "sucks" today
|
|
|
|
|
Have a look at
http://www.componentsource.com[^]
And look either for component suites that contain specialized versions of the most used components OR look for components that let you "skin" the standard .NET components
Good luck
|
|
|
|
|
If none of the answers here are what you are looking for, then please be more specific: What look are you looking for? What do you want you controls to look like?
Don't start a new thread just because you don't like the answers here...
|
|
|
|
|
Actually I am using .netFramework 2.0 and VS 2005.
Now I want to change look of controls of window applications.
So I need any tool or any other application which help me.
What u has suggested me , I am not getting. I need something like WPF but my framework is 2.0.
|
|
|
|
|
How to zip/Unzip a *.Wav file ?
|
|
|
|
|
like any other file, why would .WAV be any different?
use a utility, a library, WinZip with its command line extension, System.IO.Packaging.ZipPackage (.NET >=3.0)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Well, I guess the point actually is that a zipped wave (i.e. PCM wave) file often has almost the same size as the original file. Consequently, you need "compression" by some codec (speex, mp3, ...) to reduce the size while not loosing to much of the sound quality.
|
|
|
|
|
ZIP is a lossless compression utility by design; you can use it to backup/transport/restore any data you want while preserving each and every bit of the original data.
If you want a high compression ratio and accept data loss, then use something else and don't call it ZIP as it isn't ZIP, by its own definition. So your subject line should be "audio compression", and that would attract other people's attention.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
hi
my code is:
static ReaderWriterLockSlim rw = new ReaderWriterLockSlim();
static Random rand = new Random();
Thread[] AThreadReader, AThreadWriter;
Thread ThreadReaderCreator;
string sDataBase;
Boolean bWriterMustAlive;
string[] asReaderDataBase = new string[10];
private void btnRun_Click(object sender, EventArgs e)
{
AThreadWriter = new Thread[Int16.Parse(txtBNMWriters.Text)];
bWriterMustAlive = true;
for (int i = 0; i < Int16.Parse(txtBNMWriters.Text); i++)
{
AThreadWriter[i] = new Thread(fThreadWriter);
AThreadWriter[i].Name = i.ToString();
AThreadWriter[i].IsBackground = true;
AThreadWriter[i].Start();
}
ThreadReaderCreator = new Thread(fThreadCreator);
ThreadReaderCreator.IsBackground = true;
ThreadReaderCreator.Start();
}
void fThreadCreator()
{
Random r = new Random();
AThreadReader = new Thread[Int16.Parse(txtBNMReaders.Text)];
for (int i = 0; i < Int16.Parse(txtBNMReaders.Text); i++)
{
int IloopLength = Int16.Parse(txtBLowerBCReaders.Text) + r.Next(Int16.Parse(txtBUpperBCReaders.Text) - Int16.Parse(txtBLowerBCReaders.Text));
for (int j = 0; j < IloopLength; j++) ;
AThreadReader[i] = new Thread(fThreadReader);
AThreadReader[i].Name = i.ToString();
AThreadReader[i].IsBackground = true;
AThreadReader[i].Start();
}
}
void fThreadWriter()
{
Random r = new Random();
int ID = Int16.Parse(Thread.CurrentThread.Name);
int news = ID;
while (bWriterMustAlive)
{
int IloopLength = Int16.Parse(txtBLowerBCWriters.Text) + r.Next(Int16.Parse(txtBUpperBCWriters.Text) - Int16.Parse(txtBLowerBCReaders.Text));
for (int i = 0; i < IloopLength; i++) ;
sDataBase = "";
for (int i = 0; i < Int16.Parse(txtBNumbersInString.Text); i++)
{
while (true)
{
rw.EnterWriteLock();
sDataBase += news.ToString() + " ";
rw.ExitWriteLock();
}
}
news += Int16.Parse(txtBNMWriters.Text);
}
}
void fThreadReader()
{
int ID = Int16.Parse(Thread.CurrentThread.Name);
changeAmountOfProgressBar(ID+1);
for (int i = 0; i < sDataBase.Length; i++)
{
asReaderDataBase[ID] += sDataBase[i];
}
if (ID == Int16.Parse(txtBNMReaders.Text) - 1)
{
bWriterMustAlive = false;
}
}
but I can,t Slove Readers Writers Problem
what is the Prblem?
|
|
|
|
|
shahramkeyboard wrote: but I can,t Slove Readers Writers Problem
What readers writers problem?
There is a lot of code there, it would help if you, at least, gave some sort of clue as to where the code is failing. Are there any compiler error messages? Any run-time Exceptions? Are you getting different results than you expect, if so how are they different?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
shahramkeyboard wrote: what is the Prblem?
Seriously...what is the problem?
We have no clue unless you tell us exactly how it isn't working.
And why, in god's name, would you ever write
while (true)
Did you just want an infinite loop in your code?
AFAIK, rw.EnterWriteLock will not throw an error in your case, so you will never get out of that while loop.
|
|
|
|
|
You've posted too much code without any explanation as to what type of problem you are encountering is. I will point out, though, that you make way too much use of Int16.Parse(txtBNMReaders.Text) . First of all, Don't Repeat Yourself (this is known as the DRY principle); parse it once and make use of the parsed value. Secondly, what happens if txtBNMReaders.Text says A1? Always prefer to use .TryParse over .Parse .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi People.
I wonder if any of you have used a API that can detect if a button is still being clicked. Meaning, my button scrolls a ListView but i must click again and again to scroll down one Item after each other, i wonder how i can make it like the regular scrollbar that you can keep the click and it will scroll.
Please advice.
Thanks.
|
|
|
|
|
I don't know of any API for it but shouldn't be too hard to code this by checking the mouse coordinates on the tick of a timer that can be started on MouseDown and stopped on MouseUp and MouseLeave
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks dave. But i'm sure there is a more simple solutions for this
|
|
|
|
|
Actually using MouseDown instead of Click is a pretty simple answer. What do you find so complicated about it?
|
|
|
|
|
Apparently you're not
Everything makes sense in someone's mind
|
|
|
|
|