Why "threading" is unknown for visual studio? - c#

I include using System.Windows; but threading still it doesn't exist in the namespace
?!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Net.Mail;
using System.Net;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows;
using System.Timers;
using Graduation_Project;
namespace GP
{
public partial class Register : System.Web.UI.Page
{
static int count = 0;
static int timer = 600;
protected void Page_Load(object sender, EventArgs e)
{
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 600000); // 600000 Milliseconds
dt.Tick += new EventHandler(dt_Tick);
}
still have aproblem

System.Windows.Threading.DispatcherTimer is in WindowsBase.dll assembly. Make sure you have added reference to that assembly.
MSDN -
UPDATE -
DispatcherTimer is meant for WPF and Silverlight apps. It can't be used for asp.net project. Instead you should use Timer class meant for web projects.

DispatcherTimer class belongs on System.Windows.Threading namespace which it's belongs in WindowsBase.dll
Be sure you added the right assembly in your project. It is proably in C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 folder..

Related

UI TestStack White Get Value from a DataCell

Does anyone know how to get Vlaue from a ""DataCell(DataGridViewTextBoxCell)"?
I need to get a value from DataCell using its "Name" = "Symbol Row 0" or "RuntimeId" = "42 1966418 3 1 0"".
My current code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.WindowItems;
namespace UI_006
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Application application = TestStack.White.Application.Attach(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Window Calcwindow = application.GetWindow(SearchCriteria.ByText("toto"), InitializeOption.NoCache);
application.WaitWhileBusy();
}
}
}
My UISpy SceenShot:

how to get cpu state in C#

I am new to C# and programming in general.
I have created a simple plc programme (step7), simulated on PLSIM simulator.
and i want to control this programme with a WPF Interface in C# using Siemens S7ProSim COM Object reference.
here is the problem:
when i want to assign the CPU State to my label, this message is shown:
Error 1 'System.Windows.Controls.Label' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Windows.Controls.Label' could be found (are you missing a using directive or an assembly reference?) C:\Users\Lenovo\Documents\Visual Studio 2010\Projects\CSProject\CSProject\MainWindow.xaml.cs 32 28 CSProject
here is my proramm and my wpf interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CSProject
{
public partial class MainWindow : Window
{
public S7PROSIMLib.S7ProSim ps = new S7PROSIMLib.S7ProSim();
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ps.Connect();
label_CPUState.Text = ps.GetState();
labelScanMode.Text = ps.GetScanMode().ToString();
}
}
}
Thanks a lot.
I believe you want the Content property of the Label, not the Text property. Text is Winforms.
So, simply:
labelScanMode.Content = ps.GetScanMode().ToString();

Error Message is not clear to me

i Keep getting this error message and can't figure out why?
Compiler Error Message: CS1513: } expected
here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void gettickvalue(object sender, EventArgs e)
{
Random RandomNumber = new Random();
int n = RandomNumber.Next(1, 9);
imgBanner.ImageUrl = System.String.Concat("Timer/banner_", n.ToString(), ".jpg");
}
If what you posted is your whole class, you're missing a curly brace. Exactly as the error message says.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void gettickvalue(object sender, EventArgs e)
{
Random RandomNumber = new Random();
int n = RandomNumber.Next(1, 9);
imgBanner.ImageUrl = String.Concat("Timer/banner_", n.ToString(), ".jpg");
}
} //we added this curly brace
It's easier to see where it's missing if you format your code properly. Visual Studio can do this for you, look it up to see how in your version. I'm on Visual Studio 2010 Pro, so I go to Edit -> Advanced -> Format Document.
Notice also that I changed your concatenation function to just be String.Concat instead of System.String.Concat. No need to put the system reference in front of it because the namespace is already referenced by your first using statement.
I also suggest you rename your function. See General Naming Conventions on MSDN.

How to get grid items --wpf

I made WPF application named as WpfApplication7.It has several folders. One of them is named as Assign_Rights . I have created a UserControl in this folder and named it as Assignment_Rights. Inside this user control i have created a grid and bind it to data explicitly! Now There is button name as Click New. It shows me that PK(Primary Key-Value) of a selected item from grid.
User n = grid.GetRow(view.FocusedRowHandle) as User;
int abc = n.Primary_Key;
Question: As i wrote code to get PK of Selected item it generated error at
int abc = n.Primary_Key;
by saying
Error 'WpfApplication7.Assign_Rights.User' does not contain a definition for 'Primary_Key' and no extension method 'Primary_Key' accepting a first argument of type 'WpfApplication7.Assign_Rights.User' could be found (are you missing a using directive or an assembly reference?) D:\Backup_WPFAppliacation7\New folder\WpfApplication7\WpfApplication7\Assign_Rights\Assignment_Rights.xaml.cs 59 28 WpfApplication7
How to Solve this Error?
EDIT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
namespace WpfApplication7.Assign_Rights
{
public partial class Assignment_Rights : UserControl
{
int useridd;
nrcsaEntities d = new nrcsaEntities();
public Assignment_Rights()
{
InitializeComponent();
}
private void ToggleButton1_Click_1(object sender, RoutedEventArgs e)
{
if (view.IsRowSelected(view.FocusedRowHandle) == false)
{
DXMessageBox.Show("Please Select any Item From Grid List");
}
else
{
User n = grid.GetRow(view.FocusedRowHandle) as User;
int abc = n.Primary_Key;
var getd = from p in d.Users select p;
MessageBox.Show(view.FocusedRowHandle.ToString());
} . . . .

C# and Microsoft Speech.Recognition and Speech.Synthesis

I'm new to C# and I'm new to Speech.Recognition.
I searched very long for tutorials but didn't find that much, I'm even not quiet sure whether I included everything correctly.
I downloaded:
SDK
Runtime
Languages
I'm programming local, I have Windows XP, .net framework 3.5.
Now I just want to get started with some simple lines of code, like to say "hello world" or say one or two words as input.
I tried following, and of course it doesn't work :>
error:
"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer foo = new SpeechSynthesizer();
foo.Speak("Test");
}
}
}
edit:
hello,
i tried you code,but
using SpeechLib;
couldn't be found :>
well now i wrote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;
namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
but I get an error with:
numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout
Project + Add Reference, .NET tab, select "System.Speech".
A project template pre-selects several .NET assemblies. But only common ones, like System.dll, System.Core.dll, etcetera. You have to add the 'unusual' ones yourself.
you can try this:
get Interop.SpeechLib.dll
using SpeechLib;
private void ReadText(string readText)
{
int iCounter = 0;
while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
{
SpVoice spVoice = new SpVoice();
spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
spVoice.WaitUntilDone(Timeout.Infinite);
iCounter = iCounter + 1;
}
}

Categories