|
I started with console, i'll move it to class library, and eventually i'll add a dll as a reference.
|
|
|
|
|
First of all, you are not really dealing with multiple 'threads' here. Yeah, each process executes on its own thread, but you are really not writing a multi-threaded application.
You are writing two applications.
Your question is REALLY about how to get the two applications to talk to one another.
There a bunch of ways you can do that. Use sockets, use web services, etc...
But first ask yourself the big question....
WHY are you forcing yourself to use this design?
What is requiring you to set this up in this way?
|
|
|
|
|
what do you mean "why i forcing myself..."
I implemented some algorithm, and now i want to ad an ui...
also i would like to build some data base of users, ans store there their profiles.
so far i have three different projects (for each layer) what wrong with that ?
|
|
|
|
|
You need to go back and look at your wording though...
You state that you main application (you call Thread A) is a windows/wpf application and that it launches 'a console app' (that you refer to as Thread B0 that takes care of some backside processing based upon the answer, but no matter there...
The fact that they are separate processes is a bit concerning because now you are spinning of a completely different application (process) that you have specified as a console application to do processing in the background, when in reality it sounds like what you really want to do is just create a new process that is part of your existing application, throw it up on a new thread so it can run independently of the main thread (not a bad thing) and then do your processing as needed.
In reality, if you use separate physical processes, you ARE creating different threads. Each individual process gets it's own thread of execution... but now you need to deal with inter-process communication options like pipes, web services, sockets, etc...
I would just build a class to contain your additional processing, spin an instance of that up internally and use events to pass data back to the main thread when you need to update something visually. Dealing with an app that has multiple individual PROCESSES can be a real pain to maintain, debug, and extend latter on.
|
|
|
|
|
Thanks for the detailed answer...
First, my logic is not a console app, it started with console, but then i wrote it from scratch as a dll.
AS your advice, i put my logic into additional class, and i use events to pass data, but i still have some problems with the recursion which should be idled when it waiting to the users answer...
|
|
|
|
|
Sorry, I have been away for a while on vacation...
I am a bit confused when you mention recursion... if you are just sitting there waiting for a user to answer a question then you are really not using recursion.... you really just need to let that thread spin on and wait for a request from the client. Just put the processing in your separate thread into a loop that keeps it cycling until it gets a request from the host to perform some processing. Because it is on a separate thread it will not interfere with processing while it is just waiting.
Usually you just wrap everything in your thread function inside a do loop that watches for different flag settings to know when it needs to abort and end or process some data.
|
|
|
|
|
Hi,
When i say recursion, i mean that the flow of the algorithm will repeat it self depending the user input
|
|
|
|
|
We have many windows services on several servers.
How do you suggest to build a silverlight 4.0 application which monitors these services on servers?
I am thinking to have a functionality to check the status of each service on each server every so often i.e. every few seconds...
What are your thoughts please?
Thanks
|
|
|
|
|
You'd have to communicate with a backend web service, which polled these services to see if they were running or not. The Silverlight application would trigger the web service periodically (say every 10 seconds) and the results would be updated in a notifiable object.
|
|
|
|
|
Do you mean like having a timer inside a WCF to monitor changes every so often?
And then use the silverlight to check the WCF?
Please elaborate.
Thanks
|
|
|
|
|
I'd initiate this from the Silverlight side if I were you. Have Silverlight request the information from the service at timed intervals.
|
|
|
|
|
Do you mean to have the silverlight app to call the (WCF which checks all the windows services) ?
Thanks
|
|
|
|
|
|
|
You could also building an SL4 options with OOB option and COM support, but this could check windows services running on the client and not on the server.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Again on with my quest to learn WPF controls and improve our standard controls library to make it easier to use within a MVVM environment.
In this case I am looking for sggestions for how to best implemnt a standard button.
I would like to create a standard button which has an image and caption.
I understand that this is easily achieved using xaml, but ideally we would like a standard implementation so the button could be used in the following manor.
<CustomControls:StandardButton ButtinImage="Logout.jpg" ButtonCaption="Button Text"/>
How would you achieve this?
1. Inherit from the button class and add dependancy properties
2. Use Attached Properties and a style
3. Inherit fron UserControl using dependancy properties fro the image and caption
Thanks for your time
Just racking up the postings
|
|
|
|
|
I would, personally, go for 1 or 2.
2 is good if you are clear on how to create attached properties.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
If i go for one, I am assuming that I can do away for a controltemplate and just set the content to be an image object and a label programitcally based on the dependancy properties.
Does this sound right?
Just racking up the postings
|
|
|
|
|
If you want to have a bit of fun, you could always create a Blend Behavior which set the Content of the button.
|
|
|
|
|
Not sure that sounds like fun...
Just racking up the postings
|
|
|
|
|
It does to me (and it's very easy to do).
|
|
|
|
|
Afternoon Guys and Gals,
I am trying to learn how to implement Custom Controls in WPF for use in a reusable controls library because I am not happy with the current implementation as our current method does not play well with MVVM.
As an experiment I am trying to create a custom control that has two ListViews and two buttons, the idea being to allow a user to bind to SelectedItems and DeSelectItems properties in the view. These will populate the two list boxes from properties in a viewmodel. The buttons simply allowing the user to select an item and move it from one ListView to the other, ie selected / not selected.
The problem I have is that when I bind to the SelectedItems and DeSelectedItems in xaml, neither dependancy property in the custom control actually get populates, ie the lists stay empty.
I believe my mistake is related to Binding Source, something I do not understand so well
The Custom Control Source - (The Test application is implemented as MVVM)
namespace CustomControlLibrary
{
[TemplatePart(Name = DualListControl.ElementNotSelectedList, Type = typeof(ListView))]
[TemplatePart(Name = DualListControl.ElementSelectedList, Type = typeof(ListView))]
[TemplatePart(Name = DualListControl.ElementSelectButton, Type = typeof(Button))]
[TemplatePart(Name = DualListControl.ElementDeselectButton, Type = typeof(Button))]
public class DualListControl : Control
{
const string ElementNotSelectedList = "ElementNotSelectedList";
const string ElementSelectedList = "ElementSelectedList";
const string ElementSelectButton = "ElementSelectButton";
const string ElementDeselectButton = "ElementDeselectButton";
ListView _NotSelectedList, _SelectedList;
Button _SelectButton, _DeselectButton;
RelayCommand _SelectItemCommand, _DeSelectItemCommand;
static DualListControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DualListControl), new FrameworkPropertyMetadata(typeof(DualListControl)));
}
public DualListControl()
{
_SelectItemCommand = new RelayCommand(p => SelectItemCommandExecute(), p => SelectItemCommandCanExecute);
_DeSelectItemCommand = new RelayCommand(p => DeSelectItemCommandExecute(), p => DeSelectItemCommandCanExecute);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_NotSelectedList = GetTemplateChild(ElementNotSelectedList) as ListView;
_SelectedList = GetTemplateChild(ElementSelectedList) as ListView;
_SelectButton = GetTemplateChild(ElementSelectButton) as Button;
_SelectButton.Command = _SelectItemCommand as ICommand;
_DeselectButton = GetTemplateChild(ElementDeselectButton) as Button;
_DeselectButton.Command = _DeSelectItemCommand as ICommand;
}
bool SelectItemCommandCanExecute { get { return true; } }
bool DeSelectItemCommandCanExecute { get { return true; } }
void SelectItemCommandExecute()
{
if (!SelectItemCommandCanExecute)
return;
}
void DeSelectItemCommandExecute()
{
if (!DeSelectItemCommandCanExecute)
return;
SelectedItems.Add(_NotSelectedList.SelectedItem);
DeSelectedItems.Remove(_NotSelectedList.SelectedItem);
int i = 0;
}
public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<object>), typeof(DualListControl), new UIPropertyMetadata(new ObservableCollection<object>()));
public static readonly DependencyProperty DeSelectedItemsProperty =
DependencyProperty.Register("DeSelectedItems", typeof(ObservableCollection<object>), typeof(DualListControl), new UIPropertyMetadata(new ObservableCollection<object>()));
public ObservableCollection<object> SelectedItems
{
get { return (ObservableCollection<object>)GetValue(SelectedItemsProperty); }
set { SetValue(SelectedItemsProperty, value); }
}
public ObservableCollection<object> DeSelectedItems
{
get { return (ObservableCollection<object>)GetValue(DeSelectedItemsProperty); }
set { SetValue(DeSelectedItemsProperty, value); }
}
}
}
The Generic.xaml
<Style TargetType="{x:Type local:DualListControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:DualListControl}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" Name="ElementNotSelectedList" ItemsSource="{Binding Path=DeSelectedItems}"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Grid.Row="1" Name="ElementSelectButton" Margin="5" Content="<"/>
<Button Grid.Row="2" Name="ElementDeselectButton" Margin="5" Content=">"/>
</Grid>
<ListView Grid.Column="2" Name="ElementSelectedList" ItemsSource="{Binding Path=SelectedItems}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The View
<UserControl x:Class="TestApplication.Views.MainAppView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:CustomControls="clr-namespace:CustomControlLibrary;assembly=CustomControlLibrary"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<CustomControls:DualListControl SelectedItems="{Binding SelectedItemsA}" DeSelectedItems="{Binding DeslectedItemsA}"/>
</Grid>
</UserControl>
The Modelview
namespace TestApplication.ViewModels
{
public class MainAppViewModel : BaseViewModel
{
ObservableCollection<object> _SelectedItems = new ObservableCollection<object>(),
_DeSelectedItems = new ObservableCollection<object>();
public ObservableCollection<object> SelectedItemsA
{
get { return _SelectedItems; }
}
public ObservableCollection<object> DeSelectedItemsA
{
get { return _DeSelectedItems; }
}
public MainAppViewModel()
{
_DeSelectedItems.Add("One");
_DeSelectedItems.Add("Two");
_DeSelectedItems.Add("Three");
_DeSelectedItems.Add("Four");
}
}
}
Appreciate anyone who can help to identify my mistake(s), 5's in the lounge as a possible bribe?
Just racking up the postings
|
|
|
|
|
I think I see your problem.
You guessed right... Your binding sources aren't set. By default, the binding source is the DataContext, and that's not what you want here. Since those bindings are inside the control template, you want to bind to the "TemplatedParent" (It's one of the options for RelativeSource).
ItemsSource="{Binding Path=SelectedItems,RelativeSource={RelativeSource TemplatedParent}}"
Even easier, though... There's a shortcut for that, which does exactly the same thing...
ItemsSource="{TemplateBinding SelectedItems}"
|
|
|
|
|
Ian,
Firstly, thanks for taking the time to look.
I have tried your suggestion and it has not yet resolved the problem, I do believe however that you have got me somewhat closer.
While trying this out, I notice that the actual dependancy properties SelectedItems and DeSelectedItems on the DualListControl class are not being set by the bindings, ie they are empty lists even though they shold (as far as I understand) be the same lists as thoose specified in the MainAppView.
With my test data, I am expecting the DualListControl.DeSelectedItems to contain the items "One", "Two", "Three", "Four" if you see what I mean.
Any ideas?
Paul
Just racking up the postings
|
|
|
|
|
Guess we only fixed half of the problem then... Now the template should be properly bound to the parent control, but are the parent control's properties actually binding to a MainAppViewModel?
Somewhere in your window code (Or wherever the MainAppView control is contained), you need to set the DataContext to a MainAppViewModel... Otherwise, the control has nothing to bind to.
|
|
|
|