|
This is probably the best book about regex you can get:
http://www.amazon.com/exec/obidos/tg/detail/-/1565922573/104-5681665-2239906?v=glance
The {6,9} is only valid for the \d.
If you need it for the whole string you would need to do something like this: (regex\d{2,5}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I am trying to use a foreach to loop through a few datasets to update a table. With the code I have it is not working. I have checked both datasets with the quickwatch to make sure they are populated and they are. It runs through the code once, but on the second time through I get an error that the "SqlHelper.ExecuteScalar(Session["connect_string"].ToString(), System.Data.CommandType.Text, update).ToString();" statement, "Object not set to reference". I inserted a breakpoint and found that the Session variables are not changing in the update statement that I am creating. Any help would be appreciated.
foreach(DataTable mbTable in mb.Tables)
{
foreach(DataRow mbRow in mbTable.Rows)
{
Session["id"] = mbRow["m_id"].ToString();
Session["order"] = mbRow["m_ord_number"].ToString();
string dtdate = "SELECT stp_arrivaldate FROM stops WHERE ord_hdrnumber = '" + txtOrder.Text + "'";
DataSet dt = new DataSet();
dt = SqlHelper.ExecuteDataset(Session["connect_string"].ToString(),
System.Data.CommandType.Text, dtdate);
foreach(DataTable dtTable in dt.Tables)
{
foreach(DataRow dtRow in dtTable.Rows)
{
Session["dtdate"] = dtRow["stp_arrivaldate"].ToString();
string update = "UPDATE masterbrand_appt SET m_delivery_date = '" + Session["dtdate"].ToString() + "' WHERE m_id = '" + Session["id"].ToString() + "' AND m_ord_number = '" + Session["order"].ToString() + "'";
SqlHelper.ExecuteScalar(Session["connect_string"].ToString(),
System.Data.CommandType.Text, update).ToString();
}
}
}
}
Scott Moore
|
|
|
|
|
Why are you using session variables in this way? I can see nothing but trouble coming from that.
I suppose that you only get one record in the result from the select query? Why do you loop through all of the tables (a single one) and all of the rows (a single one)?
---
b { font-weight: normal; }
|
|
|
|
|
after a response I recieved through a C# yahoo group I completely agree. A man by the name of Brian showed me how to do it with SQL, which is how I wanted to do it, but could not figure it out.
Thanks for the reply.
Scott Moore
|
|
|
|
|
How do I put additional data in the request header array and how do I pick up that information on the server side?
I've created a custom sink and now I want to put data in the request header array to be able to pass additional information to the server side. But I don't know how to do it and I haven't found any descriptive example.
I thought that the ProcessMessage method on the client side was used to do it. But as I also has the IMessageSink.SyncProcessMessage in the class, it seems that the ProcessMessage method is never called.
I've seen examples (though I don't know if the work), where the request header array is assigned data on the client side, and the array is read on the server side. But those examples don't have the sink class inhereting from IMessageSink.
Any advice or example is helpful, thank you
|
|
|
|
|
The crucial thing here, is where the custom sink is intended to be placed. That is, before or after the formatter sink. If the custom sink is placed before the formatter, you work on the message. On the other hand, if the custom sink is placed after the formatter, you work on the stream.
My intentions was to have my custom sink "above" the formatter sink. And, if the first client sink shall be placed "above" the formatter sink, the IMessage interface needs to be implemented. This was why I had IMessageSink.SyncProcessMessage method in my class of course. In this situation you work on the message, and any manipulation to the message is done in the IMessageSink.SyncProcessMessage (or IMessageSink.AsyncProcessMessage) method. That's why the ProcessMessage method on the client side never was called.
This code snippet shows how to add some information to the message:
public IMessage SyncProcessMessage(IMessage msg)<br />
{<br />
msg.Properties.Add("Animal", "Fox");<br />
IMessage retMsg = ((IMessageSink) nextSink).SyncProcessMessage(msg);<br />
return retMsg;<br />
}
If you rather have your custom sink after the formatter sink, then it is the ProcessMessage method you're supposed to use. If so, the IMessageSink.SyncProcessMessage is not called. In this case you manipulate the array header to pass information to the server side, as follows:
public void ProcessMessage(System.Runtime.Remoting.Messaging.IMessage msg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)<br />
{<br />
requestHeaders["Animal"] = "Fox";<br />
<br />
nextSink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders, out responseStream);<br />
}
In both cases, the ProcessMessage method on the server side is responsible to get the added information. But you use requestHeaders if you working on the stream, or the requestMsg if you're working on the message.
public ProcessMessage(IServerChannelSinkStack sinkStack, System.Runtime.Remoting.Messaging.IMessage requestMsg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out System.Runtime.Remoting.Messaging.IMessage responseMsg, <br />
out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)<br />
{<br />
string msg = requestHeaders["Animal"] as string;
msg = requestMsg.Properties["Animal"] as string;
...<br />
...<br />
}<br />
|
|
|
|
|
Why in the world would Microsoft's new Studio 2005 give you something as fun as a transparency property for Forms, and not put that property in for all controls? I would really like to create an application that has transparent buttons, and when the user mouseOvers on the button, the buttons become clearer. I thought it would be a simple tasks, but I just could not get it done. I ended up faking it by having mini forms floating on top of my application, each with a transparency, but it looks buggy when you drag the application around. I want it docked like all other controls, but if you try to make your own custom control that extends from Form, it fails to dock because it considers Forms that the ultimate container so you can't but a Form into anything.
I do have some OpenGL experience, and could have a constantly running thread in my application that checks for mouse positions and draws GDI bitmaps to a drawing area with different levels of Alpha. However, I'm really hopping that I can do it more simply than that. Anyone have any ideas, or tried getting other controls to have transparency?
|
|
|
|
|
Hi,
I have an application which was developed in C# .NET , however this application uses some 3rd party controls which are available on the web for free,. during my setup process how should i pull those libraries at run time and install them on the user's desktop.
Any ideas would be great or any sample would be even nice.
I have build simple .MSI file using visual studio setup.
thanks in advance
Samar Aarkotti
|
|
|
|
|
Any dependant Dlls shoudl be automatically pickup up when you create the MSI install project by VS.NET. They will be included in the deployment package and written to the program directory by default.
Basically as long as you have a refernce to the controls in your project, the MSI should take care of it.
|
|
|
|
|
I know those things , but how do i get all the dll's at the runtime, so that MSI will pick those dlls from internet.
|
|
|
|
|
You would probably need to write an application that runs during the MSI installer or b4 your application runs for the first time to download them.
|
|
|
|
|
Hi for all
I'm studying Threads, Mutex and so on. About Mutex, I've readed that Mutex is to synchronize threads and processes. When a thread releases the Mutex, another thread can obtain it and do something. But when I was seeing some source codes the reality isn't this. I'll explain. When a Thread creates the Mutex and set itself like the ownership, the current thread is the creator and the owner. When the Mutex is released to some waiting thread, these waiting thread only just receive a signal and then do something, and it doesn't have exclusive access to the resource . A sample:
class Myclass
{
Mutex newMutex = new Mutex(true);
public static void Main()
{
Thread newThread = new Thread(new ThreadStart(AccessMutex));
Thread newThread2 = new Thread(new ThreadStart(OtherAccessMutex));
newThread.Start();
newThread2.Start();
Thread.Sleep(2000);
newMutex.ReleaseMutex();
}
public void AccessMutex()
{
newMutex.WaitOne();
Console.WriteLine("Done");
}
public void OtherAccessMutex()
{
newMutex.WaitOne();
Console.WriteLine("Done");
}
}
Other doubt: If two threads have call the WaitOne method of Mutex's object, who will access the resource first?
Thanks a lot for help, threads are a great challenge.
|
|
|
|
|
You need to add a call to newMutext.ReleaseMutex() at the end of both AccessMutex and OtherAccessMutex, otherwise one of the threads will be suspended indefinitely.
For your other question, usually the threads are released in a first in first out queue, but that doesn't mean they always will. In general it is an error to assume there is a specific release order for any resource unless it explicitly states it.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I tested this sample and the two threads works fine Andy. Both of them are executed normally. But my question is, if in a main thread the Mutex is created and owned, how can I obtain exclusive access to Mutex for another thread and not just to execute the others when the main thread release it?
Thanks a lot for your help, can you help me another time? Please..
|
|
|
|
|
I think this might make things clearer.
Your code works because C# is smart enough to release the mutex when the thread ends allowing the other thread to continue, but this is a really bad habit to get into since it can lead to deadlocks. Every call to WaitOne should be paired with a call to ReleaseMutex, and this includes the mutex creation because in some processes the mutex static constructor could be called on a separeate thread from main.
ReWrite your sample methods so they look like this, then try it with the Release line commented out and in place.
static void Main(string[] args)
{
sMutex = new System.Threading.Mutex(true);
thread1 = new Thread(new ThreadStart(t1));
thread2 = new Thread(new ThreadStart(t2));
thread1.Start();
thread2.Start();
sMutex.ReleaseMutex();
thread1.Join();
thread2.Join();
}
private static System.Threading.Thread thread1;
private static System.Threading.Thread thread2;
private static System.Threading.Mutex sMutex;
static void t1()
{
for(int i=0; i<10; ++i)
{
sMutex.WaitOne();
Console.WriteLine("done1");
Thread.Sleep(0);
}
}
static void t2()
{
for(int i=0; i<10; ++i)
{
sMutex.WaitOne();
Console.WriteLine("done2");
Thread.Sleep(0);
}
}
One way you will get alternating done1 and done2 lines and the other you will get 10 donex followed by 10 doney, where y or x are 1 or 2.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Right, but there are some question remaining:
- The WaitOne method blocks the calling thread(in this case t1 and t2). After the ReleaseMutex method of Main(), the two threads executes the loop one time, cause (in my mind) this 2 threads will be blocked by WaitOne method and cause no one is signaling for the two threads. I've executed you code and you're right, it works like you said(the two ways). What I don't understanding is the WaitOne Method and the ReleaseMutex in the two threads, if the Mutex was created in Main(), how the threads obtain the exclusive access to the Mutex, and why the ReleaseMutex is called in the two threads?
- If my explanation of WaitOne method is incorrect, tell me more about it.
Thanks again and thanks for the patience
|
|
|
|
|
Imagine the mutex as a counter.
When you call WaitOne and the counter is zero then it is incremented.
If the counter is one then WaitOne enters a loop until the counter is decreased to zero and then it is incremented to 1 and the function returns.
Whenever WaitOne returns the counter is in a one state.
ReleaseMutex decrements the counter to 0.
If no threads are in WaitOne then nothing happens, but if there is a thread executing waitOne it bumps the counter back to 1 and then continues on.
That is the simplest conceptual model of a mutex. In windows terminology that is a single count semaphore which is sometimes called a mutex in other operating systems.
In windows and .net the mutex keeps track of which thread owns it. Imagine this as a counter plus a field for the threadID of the owning thread. That's how your sample worked. When each thread went out of scope all mutexes with that flag set to the threadID were released, which allowed other threads executing WaitOne to return. A thread owns the mutex when it exits from WaitOne because the mutex structure is locked and the threadID of the owner is recorded. Also through the magic of the thread scheduler, threads executing WaitOne are suspended and one is selected to wake up when releaseMutex is called rather then looping indefinitely.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Ahhh, now I understand. When we call WaitOne() the thread wait for the Mutex and when the Mutex is released, the thread acquires access about it. After the current thread use the Mutex, it is released to the other thread acquires the access to Mutex and use it.
Thanks, that was exactly what I wasn't understand, the WaitOne acquires the access to Mutex when it is released.
Thanks Andy for the support.
|
|
|
|
|
Ahhh, now I understand . When we call WaitOne() the thread wait for the Mutex and when the Mutex is released, the thread acquires access about it. After the current thread use the Mutex, it is released to the other thread acquires the access to Mutex and use it.
Thanks, that was exactly what I wasn't understand, the WaitOne acquires the access to Mutex when it is released.
Thanks Andy for the support.
|
|
|
|
|
Hi,
Can you help me about show a MDI child without flickering?
The Mdi child form have no border and no control box, but when i execute
then form.show appear then border briefly and then disapear.
Is it a bug?
|
|
|
|
|
I need to create a list view con 3 column.
The first one will contain images 32x32 the second one the real size of them 500x125 or 423x90... the last one just the name.
Ok how can i create a list view like this?
|
|
|
|
|
First you need to add three columns to the ListView 's Columns collection, either with the designer or by code:
ColumnHeader ch = new ColumnHeader();
ch.Text = "";
ch.Width = 35;
listView1.Columns.Add(ch);
ch = new ColumnHeader();
ch.Text = "Size";
ch.Width = 80;
listView1.Columns.Add(ch);
You then need to create an ImageList and add all the 16x16 images that could be displayed (while in detail view 16x16 pixel images are displayed), and then set the image list to the ListView control:
ImageList il = new ImageList();
il.Images.Add(bm1);
il.Images.Add(bm2);
listVie1.SmallImageList = il; Finally you add the items:
ListViewItem item = new ListViewItem("");
item.ImageIndex = 0;
item.SubItems.Add(String.Format("{0}x{1}", widht, height);
item.SubItems.Add(fullPath);
listView1.Items.Add(item);
I hope this helps. Any questions feel free to ask again.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
yes but i detail display mode (with coulmn) it is not displayed images, but just when iconList or Largicon.
Then i need to set bigger images then 16x16, can i?
Then can i set different image size in preview so to have 16x16 for 1 item, 32x30 the second, 30x25 the third...
tnx for your help.
|
|
|
|
|
In detail view you can also display images (see detail view in Windows Explorer for an example.) You just have to set the ImageIndex property of the ListViewItem and a SmallImageList to the ListView .
But you can't set different image size for each item. Since you specify images in an ImageList , they are all required to have the same size.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|