Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7891191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:33:19+00:00 2026-06-03T06:33:19+00:00

Introduction : I have a Server [ WCF service library ] and Client [

  • 0

Introduction: I have a Server [WCF service library] and Client [Winform], client connects to server using netTcpBinding.

the server job is to share Computer Files to the client with a file manager features { New Folder,Move,Copy,Delete,Properties, Attributes and SEARCH }.

enter image description here

The Problem :
the search function is a recursive function, it adds item to client ListView instantly (using client CALLBACK) when it finds a (folder/file) name that contains the search key.

so it was all working perfect, until I added a stop search button, which suppose to allow the user to stop the recursive function _Search(), what happens when I try to stop searching is freezing the GUI and never get back from freezing mode till I “STOP Debugging”.

In fact when I set points to see what’s wrong with the search function in debugging mode, it works and the search stops.

This’s the Code I use for searching:

WCF lib Side:

     [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
  public class MainService : IFileManager,ITaskManager
  {

    IFileManagerCallback callback = OperationContext.Current.GetCallbackChannel<IFileManagerCallback>();

 bool stopSearch = false;

    public void StopSearch()    //client call this function to stop SEARCHING.
    {
        stopSearch = true;
    }

    public void Search(string path, string name)     //client call this function to start searching
    {
        _Search(path, name);
        callback.SearchEnd();
        if (stopSearch)
        {
            callback.InfoLabel("Search Cancelled", InfoState.Info);
            stopSearch = false;
            return;
        }
        callback.InfoLabel("Search Done.", InfoState.Done);
    }

    private void _Search(string path, string name)    //the evil recursive function
    {
        if (stopSearch) return;
        DirectoryInfo Roots = new DirectoryInfo(path);

        foreach (FileInfo file in Roots.GetFiles())
        {
            if (stopSearch) return;
            if (file.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                _File item = new _File();
                item.Name = file.Name;
                item.Size = file.Length;
                item.Path = file.FullName;
                callback.File(item);
            }
        }
        foreach (DirectoryInfo folder in Roots.GetDirectories())
        {
            if (stopSearch) return;
            if (folder.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                _Folder item = new _Folder();
                item.Name = folder.Name;
                item.Path = folder.FullName;
                callback.Folder(item);
            }
            _Search(folder.FullName, name);
        }
    } 
 }

WCF Interface:

  [ServiceContract(CallbackContract = typeof(IFileManagerCallback))]
public interface IFileManager
{
    [OperationContract]
    void StopSearch();
     [OperationContract(IsOneWay = true)]
    void Search(string path, string name);
}

     public interface IFileManagerCallback
{
    [OperationContract]
    void File(_File file);

    [OperationContract]
    void Folder(_Folder folder);

    [OperationContract]
    void InfoLabel(string value, InfoState state);

    [OperationContract]
    void SearchEnd();

}

Client side :

 class Callback : IFileManagerCallback
{
    public delegate void OnFileReceived(object sender, _File item);
    private OnFileReceived _fileReceivedHandler = null;
    public event OnFileReceived OnFileReceivedEvent
    {
        add { _fileReceivedHandler += value; }
        remove { _fileReceivedHandler -= value; }
    }
    private void RaiseFileEvents(_File file)
    {
        if (_fileReceivedHandler != null)
        {
            _fileReceivedHandler(this, file);
        }
    }
    public void File(_File file)
    {
        RaiseFileEvents(file);
    }
    // **I WILL AVOID POSTING Folder event and handler it's the same of the file.**
    public void Folder(_Folder folder)
    {
        RaiseFolderEvents(folder);
    }

Client Form1.cs :

  public partial class Form1 : Form
{

       private void callback_FileReceivedEvent(object sender, _File file)
    {
        ListViewItem item = new ListViewItem();
        item.Text = file.Name;
        item.ToolTipText = file.Path;
        item.Tag = item.ImageIndex;
        item.Name = item.Text;
        item.SubItems.Add(CnvrtUnit(file.Size));
        item.Group = listView1.Groups[0];
        item.ImageIndex = _iconListManager.AddFileIcon(file.Path);
        listView1.Items.Add(item);
    }
    bool IsSearch = false;
    private void btnSearch_Click(object sender, EventArgs e)
    {
        if (!IsSearch)
        {
           IsSearch = true;
           listView1.Items.Clear();
           client.Search(currAddress, txtAddress.Text);
           return;
        }
        client.StopSearch();
    }
    public void StopSearching()
    {
        UpdateLabel();    //updating GUI label "Selected 0:,Items: 0"
        IsSearch = false;
    }
}

I’m really confused about fixing it, I’m not sure if I did choose the right title for my question ,so if that’s happening because I need an Async callback, how would I convert my search function and Async Callback with WCF?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:33:20+00:00Added an answer on June 3, 2026 at 6:33 am

    I think I know what is happening here, but it is just an educated guess. Since your WCF code is set to be one instance per session and you are in that same session, you are creating a circular lock. Basically, you are hitting a point where callback.File(item) is calling back into your client code at the same time that your client code is calling into StopSearch. So, the client code will not respond until it hears back from StopSearch and the server will not get to the if(stopSearch)/stopSearch = true until it hears back from the client (which is busy waiting for the WCF, which is busy waiting for the client, which is….get the point). Try marking the StopSearch as OneWay so that (I believe, my WCF isnt too strong) the call in the client will immediately return (and not wait for the WCF), thereby unlocking the client.

    Alternatively, you could make your WCF code more multithreaded, however you might run into more issues that way.

    UPDATE

    Based on your response, it does seem that you will need to make either your WCF service call truly async, or make the client code more async (using the TPL or backgroundworkers or just a new thread spun up)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Introduction We have an OpenID Provider which we created using the DotNetOpenAuth component. Everything
First a little introduction. We have an SQL Server Express 2008 database, which schema
I am implementing a WCF Data service that implements the following method: http://debugmode.net/2010/06/13/introduction-to-wcf-data-service-and-odata/ I've
Introduction I have been so annoyed by applications that have a startup dialog which
Introduction I have some sort of values that I might want to access several
Introduction In my current organisation, we have many desktop and web applications all feeding
I have a problem with a web page. The introduction of a simple <base
Just an introduction of my code... I have a view that consists of -details
I'm looking for an online introduction to unit testing and TDD. I have virtually
INTRODUCTION I'm using excel downloads as a way of users downloading a score sheet,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.