|
OK i figured out you don't have to bother... it wasn't as complicated as expected... thanks...
|
|
|
|
|
Without creating a system service that would run code on 'shuting down' what type of hook should be used by a app running in the background to know when the system is shutting down or logging off?
Programmer: A biological machine designed to convert caffeine into code. * Developer: A person who develops working systems by writing and using software.
[ ^]
|
|
|
|
|
Take a look at the SystemEvents class especially the SessionEnding event.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
nevermind.. i think ill give up for now and just use a modified spinlock!
im writing a simple lock-free queue (intended for efficient multithreaded use) and im not sure ive quite figured out the logic behind the use of Interlocked.CompareExchange(). would code like the following produce the correct result of adding a new linked list node to the tail of a list under multithreading conditions??
<br />
while (null != Interlocked.CompareExchange(ref _tail.next, newNode, null))<br />
Thread.Sleep(1);<br />
_tail = newNode;<br />
thanks in advance
-- modified at 12:40 Monday 8th January, 2007
|
|
|
|
|
Hi,
I dont think this is thread-safe: you perform two operations on the list
1. CompareExchange
2. modify tail (_tail=newNode)
the combined operations should be atomic.
And I dont think you can achieve it with the Interlocked class at all, since inserting
or removing a node to/from a linked list involves modifying two references or pointers,
which is more than any Interlocked method offers.
SO you will need a lock after all.
Luc Pattyn
|
|
|
|
|
sorry, i dont think u were very convincing, im pretty sure this would work...
- in neutral state, _tail.next is null; the end of the list.
- the first thread executes the interlocked operation which succeeds and atomically sets _tail.next to something other than null.
- this causes the interlocked operation to fail on any other thread, and spin.
- the final assignment returns _tail.next to null (as a new list node has no next-node) and the list is coherent.
i think i just answered my own question there but i do get the feeling im missing something. i have more of an issue dequeuing a list node; ascertaining just how the de/enqueue code can interfere with each other and how i can get it to safely execute in parallel.
I worship his divine shadow. ^
|
|
|
|
|
Well, yes and no:
Yes, if you have a single-linked list and a _last reference, then you can append
a node to it correctly with your code, but that's about it. If there is no _head,
and no backward link (prev), then you can not reach any other node.
A single-linked list with a head only typically uses the following logic
(I use a dummy head node to simplify code: when head.next is the first node (or null),
then head itself never changes and never is null):
void addNode(Node newNode) {
newNode.next=head.next;
head.next=newNode;
}
Node removeFirstNode() {
Node firstNode=head.next;
head.next=firstNode.next;
return firstNode;
}
the safe versions would be:
void addNode(Node newNode) {
do {
Node firstNode=head.next;
newNode.next=firstNode;
} while (firstNode!=Interlocked.ExchangeCompare(head.next,newNode,firstNode));
}
Node removeFirstNode() {
do {
Node firstNode=head.next;
} while (firstNode!=Interlocked.ExchangeCompare(head.next, firstNode.next, firstNode));
return firstNode;
}
But now there are a lot of functional limitations:
there is no access to any other node
1) we do not maintain a tail
2) we do not maintain a backward link
so we have what is known as a stack, certainly not a queue.
If we want more than stack functionality, we'd better have head+tail+nextlinks+prevlinks;
but we must perform multiple stores atomically, and you cannot achieve that
with a single Interlocked method.
You can of course synthesize a lock yourself, something like:
while (0!=Interlocked.ExchangeCompare(lockVar, 1, 0)) Thread.Sleep(1);
lockVar=0;
but that is not what you intended, is it ?
-- modified at 15:10 Monday 8th January, 2007
Luc Pattyn //
|
|
|
|
|
yes i see using a dummy node makes things a heck of a lot easier with the interlocked stuff and i had considered it but i didnt think it would make it that easy. the queue does have a head btw, from which items are removed (added to the tail). at first thought i would need to look into whether a circular reference of the head would introduce some other issue.
but for simplicity's sake (sister of felicity i believe) im gonna use a good old LinkedList and the sleeplock thing. i usually just lock () { } things but for this i certianly want to keep it lightweight. with a little modification to make it adaptive for an actual multi-processor system (ie. not relinquishing time slice) i think itll be quite scalable.
thanks for your input
I worship his divine shadow. ^
|
|
|
|
|
FYI, I tend to avoid circular linked lists; I typically use
either a single-linked list with a dummy head node,
or a double-linked list with a dummy head node and a dummy tail node (different from head);
reason is you can then walk the list forwards/backwards (without removing nodes) until
next/prev equals null.
Combining the head and tail dummies would save a node, but that is typically not worth the hassle (unless nodes are really big of course).
Luc Pattyn
|
|
|
|
|
true, and big nodes should be seen by a doctor lest they hinder the GC
I worship his divine shadow. ^
|
|
|
|
|
How do i create tab control that in runtime i can edit the tab pages names (like excel)
GALGAL
|
|
|
|
|
Where is your name?
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
My name is gal edvi .... what about my question? anyone know such component?
|
|
|
|
|
Do you mean edit the text that is displayed?
this.tabControl1.TabPages[0].Text="whatever you want";
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
sorry ... mabye i wasn't clear ... i want that the user will be able at runtime change the tab page name while the software is running ...
thanks
|
|
|
|
|
Just put a textbox on your form and put this code behind a button Click event:
this.tabControl1.TabPages[0].Name = this.textBox1.Text; This will change the first page's name.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Well, I am using Visual C# 2005 express, and I am looking to start making a nice shiny program. My question now is, on a windows Form, how can I write code behind a button so that when it is compiled and run, a new, and completely functional new button can be formed?
http://img102.imageshack.us/img102/8792/randomng3.jpg
So basically, disregarding the captions I put on the buttons, how on demand of a click, can I make an exact copy of the button clicked, 5 or however many pixels to the left (or right, or above, whatever)?
|
|
|
|
|
Do exactly what the IDE is doing for you when you place a button on a form at design time
Take those pieces of code and replicate them when you need.
SkyWalker
|
|
|
|
|
Mircea Puiu wrote: Take those pieces of code and replicate them when you need.
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(62, 54);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
}
private System.Windows.Forms.Button button1;
Ok, with some editting there is all the information regarding button1, so I have tried copying and pasting all and parts of the code into any place that makes sense, and either it tells me
"Type or namespace, or end of file expected", or it compiles and nothing happens upon button click. So then I change all the places where it says button1 to button2, and of course it tells me "We don't have a definition for button2"...
Can anyone spare the time to be a bit more specific 
|
|
|
|
|
If you SuspendLayout and do not ResumeLayout , then nothing will seem to happen
SkyWalker
|
|
|
|
|
Suppose you have
private System.Windows.Forms.Button TheNewButton;
Somewhere, you want to have a piece of code creating a new button. Here the code you need:
this.SuspendLayout();
TheNewButton = new Button();
this.TheNewButton.TextAlign = ContentAlignment.MiddleCenter;
this.TheNewButton.Width = 140;
this.TheNewButton.Height = 40;
this.TheNewButton.Text = "New button";
this.TheNewButton.UseVisualStyleBackColor = true;
this.TheNewButton.Visible = true;
this.TheNewButton.Location = new System.Drawing.Point(150, 24);
this.Controls.Add(TheNewButton);
this.TheNewButton.Click += new System.EventHandler(this.TheNewButton_Click);
this.ResumeLayout();
this.Refresh();
Then do not forget to add the TheNewButton_Click() to your form class:
private void TheNewButton_Click(object sender, EventArgs e)
{
}
SkyWalker
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
Button buttonNew = new Button();
buttonNew.Location = new Point(button1.Left + button1.Width +25, button1.Top );
buttonNew.Name = "buttonNew";
buttonNew.Size = new Size(130, 26);
buttonNew.Text = "buttonNew";
buttonNew.Click += delegate(System.Object o, EventArgs eArgs)
{ MessageBox.Show("new button clicked"); };
this.Controls.Add(buttonNew);
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I'm writing label-like control but not inheriting from anything.
And so I'm trying to add mouse events like MouseClick..
I read somewhere to put:
public delegate void MouseEventHandler(object source, int clickCount);
public event MouseEventHandler MouseClick;
public void OnMouseClick(object source, int clickCount) {
MessageBox.Show("clicked");
}
but thad doesn't seem to work..
I tried searching for it but all i found was inherited controls overriding these events..
life is study!!!
|
|
|
|
|
not registering events means not capturing events
SkyWalker
|
|
|
|
|
hello;
i want to catch that user double clicks on filled cells on datagrid but there is no event for this, is there any idea for handle it!
thanks
|
|
|
|