|
i wote next code
class SynchronizedMailBox : MailBox
{
private static ManualResetEvent mre = new ManualResetEvent(false);
private static Mutex mainMutex = new Mutex(false);
public override void Write(Message msg)
{
mainMutex.WaitOne();
if (IsEmpty())
mre.Set();
base.Write(msg);
mainMutex.ReleaseMutex();
}
public override Message Read()
{
mainMutex.WaitOne();
mre.WaitOne();
Message ms = base.Read();
if (IsEmpty())
mre.Reset();
mainMutex.ReleaseMutex();
return ms;
}
}
my question is, what will be happen when those lines will be executed
if (IsEmpty())
mre.Set();
and there are blocked thread/s on WaitOne() in read method.
the fact that write method is still under the mutex will prevent from unblocked reading thread/s to continue running ?
one more question is about if(isEmpty()) inside read method ,
do i need one more mutex to close the "if" or the main mutex which "close" the whole method is enough ?
tanks
|
|
|
|
|
|
igalep132 wrote: the fact that write method is still under the mutex will prevent from unblocked reading thread/s to continue running ?
If the 'reader' threads are sitting on MRE.WaitOne, how is the writer thread going to reach MRE.Set? Won't the writer thread me stuck at MainMutex.WaitOne since the reader thread will hold the mutex during Mre.WaitOne?
I would suggest that the best approach is to have the queue reader, if the queue is empty, reset MRE, leave the main mutex, and wait on MRE; the queue writer should set MRE unconditionally within the mutex. After every time the reader waits on MRE, it should re-check to see if the queue is empty; if not, it should re-loop.
It's tricky logic to get right, and I might have made a mistake in my description above; using the Monitor class will make things easier, but I think mutexes and manual-reset events should work.
|
|
|
|
|
Hi
I want to use one of the controls in the Code Project in a commercial appliction.
I read the license but I don't get the legal details.
I understood that I can use the control as long as I mention the copy right (or at least that is what I gathered).
My questions are:
1- Do I have to get permission from the author first to use his/her control or not?
2- Are there other obligations on me towards any other party?
Thanks much.
EK
|
|
|
|
|
ekareem wrote: 1- Do I have to get permission from the author first to use his/her control or not?
Ask the author, each article has an author and an associated license, which explains all legal recourse. If unsure, consult a lawyer
ekareem wrote: 2- Are there other obligations on me towards any other party?
Depends if the control uses any third party assemblies or code. You must check with a lawyer as any 'unmentioned' third party associations may still be at your own liability. Again, you can consult a lawyer as well as the author.
Always, always ask the author if you may use it in a commercial application and what you must do to do so. Get his/her answer in writing.
|
|
|
|
|
Regardless of the legal issues I would say it's good manners to contact the author and certainly give credit where it is do.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
when using a delayed sign assembly where should be the public key in the client pc distributed by the owner organization
|
|
|
|
|
Hi there
I have searched a lot but I didn't find any thing
I want to know about 3 things!
1.How can we create a program like osk(on screen keyboard)that have focus on itself and other application in a same time
2.is it possible to run windows .net applications in windows before windows logon as a service?
3.is it possible to locate the application in a specific part of screen in C#
if you want to understand type magnify in run (in windows xp) to see wath I mean,it changes the screen resolution and runs on top of the screen where no other programs can run,maybe another desktop!
thanks
|
|
|
|
|
faslesabz wrote: How can we create a program like osk(on screen keyboard)that have focus on itself and other application in a same time
Learning how to search, part one[^]
faslesabz wrote: 2.is it possible to run windows .net applications in windows before windows logon as a service?
You can make .net services, no .net application can start before windows loads, included your service.
faslesabz wrote: is it possible to locate the application in a specific part of screen in C#
if you want to understand type magnify in run (in windows xp) to see wath I mean,it changes the screen resolution and runs on top of the screen where no other programs can run,maybe another desktop!
This is entirely way to confusing for me to understand. You can make your own magnification type program see; searching, part 2[^]
|
|
|
|
|
I have a WPF Window that at loading time generate a variable number of image with this for cycle :
public Window1()
{
InitializeComponent();
int numPos = 5;
for (int i = 1; i <= numPos; i++)
{
Image imageStatus = new Image();
imageStatus.Name = "Image" + i;
statusGrid.Children.Add(imageStatus);
}
}
Now i need to access at this image from a timer that every 10 seconds change the image.Source Property of every image crested at runtime ..
How Can i do this ?
|
|
|
|
|
Pick a forum and stick with it.
Don't just post this in the C# and WPF forums - it is clearly WPF so just post it there. Otherwise you will annoy people and reduce your chances of getting an answer anywhere...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
|
i've found a solution , i have an ImageGrid with only Image Created at runtime :
foreach (Image ctrl in imageGrid.Children)
{
if (ctrl.GetType() == typeof(Image))
{
if (((Image)ctrl).Name == "Image1")
((Image)ctrl).Source = new BitmapImage(new Uri("pack://application:,,,/MyApplication/aleroot.png"));
}
}
with this code i change the image source for my Image Created at runtime .
Thanks anyway.
|
|
|
|
|
Firstly, I have this working in development, however when I publish to the production webserver, instead of generating the report, it asks me for login credentials again.
Here is a snapshot of my entire code behind file:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if ((ViewState["ParametersShown"] != null) &&
(ViewState["ParametersShown"].ToString() == "True"))
{
ReportListing myListing = new ReportListing();
BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() +
myListing.GetReportFileName(Session["Report"].ToString()));
}
}
protected void btnBuild_Click(object sender, EventArgs e)
{
CrystalReportViewer1.ParameterFieldInfo.Clear();
DateTime startDate = DateTime.Parse(Session["FromDate"].ToString());
DateTime endDate = DateTime.Parse(Session["ToDate"].ToString());
ParameterFields paramFields = new ParameterFields();
ParameterField crStartDate = new ParameterField();
ParameterField crEndDate = new ParameterField();
crStartDate.Name = "@StartDate";
crEndDate.Name = "@EndDate";
ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue();
ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue();
dcrStartDate.Value = startDate;
dcrEndDate.Value = endDate;
crStartDate.CurrentValues.Add(dcrStartDate);
crEndDate.CurrentValues.Add(dcrEndDate);
paramFields.Add(crStartDate);
paramFields.Add(crEndDate);
ReportListing myListing = new ReportListing();
BindReport(ConfigurationManager.AppSettings["reportlocation"].ToString() +
myListing.GetReportFileName(Session["Report"].ToString()));
CrystalReportViewer1.ParameterFieldInfo = paramFields;
ViewState["ParametersShown"] = "True";
ViewState["ReportName"] = Session["Report"].ToString();
}
private void BindReport(string FilePath)
{
ReportDocument Report = new ReportDocument();
Report.Load(FilePath);
SetTableLocation(Report.Database.Tables);
CrystalReportViewer1.ReportSource = Report;
}
private void SetTableLocation(Tables tables)
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = ConfigurationManager.AppSettings["ReportDBServerName"].ToString();
connectionInfo.DatabaseName = ConfigurationManager.AppSettings["ReportDBDBName"].ToString();
connectionInfo.UserID = ConfigurationManager.AppSettings["ReportDBUserID"].ToString();
connectionInfo.Password = ConfigurationManager.AppSettings["ReportDBPassword"].ToString();
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);
}
}
}
As detailed above, running from a local machine it works fine it is only when published to production server it asks for login details. Login details are stored in the web.config file and are correct.
Please help!
Thanks
|
|
|
|
|
Hello experts,
imagine an abstract base class CBase and two derived classes CChildOne and CChildTwo. The children represent some kinds of devices. They inherit all the stuff they have in common from CBase.
What I'm trying is to use CBase as often as possible to prevent lots of case differentiations.
I need the class at hand to tell me which icon to draw for an instance of that class. I would like CBase to have a property DeviceIcon, which is static. That way I wouldn't have to create an instance every time I need the icon. And I also would like to override that property in CChildOne and CChildTwo to always get the correct icon.
Visual Studio tells me that a property cannot use both abstract and static keywords. Anyone an idea how to get that going?
Or will I have to bite the bullet and forget about the static part?
Ciao,
luker
|
|
|
|
|
lukeer wrote: cannot use both abstract and static keywords
On the class or the field?
Either way, that wouldn't make sense. An abstract class may have a static field, but it would be shared by all its children. Are you trying to avoid that?
Do you want each child class to have its own icon to be shared among the instances of that child class?
You could probably use a static Dictionary<Type,Icon> to do that. And there may be other techniques as well.
|
|
|
|
|
PIEBALDconsult wrote: Do you want each child class to have its own icon to be shared among the instances of that child class?
That's exactly what I'm trying.
Ciao,
luker
|
|
|
|
|
something like this:
abstract class BaseClass
{
protected static readonly Icon BaseIcon = new Icon("...");
public abstract Icon DisplayIcon
{
get;
}
}
class ChildClassOne : BaseClass
{
static readonly Icon ChildIcon = new Icon("...");
public override Icon DisplayIcon
{
get { return ChildClassOne.ChildIcon; }
}
}
class ChildClassTwo : BaseClass
{
public override Icon DisplayIcon
{
get { return BaseClass.BaseIcon; }
}
}
|
|
|
|
|
Hi,
I would use a static member holding the icon for the class, and an instance member holding the actual icon for the instance, like so:
public class Base {
private static Icon baseIcon=...;
protected Icon myIcon=baseIcon;
...
}
public class Child : Base {
private static Icon childIcon=...;
public Child() {
myIcon=childIcon;
}
...
}
|
|
|
|
|
Here's a way to do it with generics -- I used strings to save time working it up.
(I think it's a bit kludgey.)
public class Base<T>
{
protected static string icon ;
public string
Icon
{
get
{
return ( icon ) ;
}
}
}
public class Child1 : Base<Child1>
{
static Child1
(
)
{
icon = "Child1" ;
return ;
}
}
public class Child2 : Base<Child2>
{
static Child2
(
)
{
icon = "Child2" ;
return ;
}
}
|
|
|
|
|
What's up with the syntax colouring?
|
|
|
|
|
the PRE tags says lang="TEXT" which disables all syntax coloring.
|
|
|
|
|
Syntax doesn't have colour.
|
|
|
|
|
Thanks a lot to everyone.
I finally added a static icon variable to each of the child classes.
The base class got an abstract Image GetDeviceIcon() method that each child class overrides returning its own child class icon. That way the icon is shared between all instances of a child class and can differ between sibling classes.
The drawback is, I have to create an instance of each class once to display the possible icons. But as I said, it's only once.
Thanks again,
luker
Ciao,
luker
|
|
|
|
|
Hi all,
I am communicating to a COM port where I send a string to the device and it returns a string. A button event triggers a string to be written and a text box is populated with the read value.
What I ultimately am trying to do is to have the text box automatically update with the returned value from the device.
I initially thought a timer event should be employed, but I'm not sure if this would be the most robust way to do this.
Thanks.
|
|
|
|